Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Regular Expressions
  4. Problem combining REGEX expressions

Problem combining REGEX expressions

Scheduled Pinned Locked Moved Regular Expressions
helpregexphpcomquestion
3 Posts 2 Posters 7 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 1567210
    wrote on last edited by
    #1

    Hello all, I'm a regex newbie and I'm stuck with regex in PCRE/PHP. First expression, I'd like to match letters, numbers or underscore but - no space at start or end - no more than one consecutive space This works fine : ^[\w]+([_\s]{1}[a-zA-Z0-9]+)*$ Second expression - no "private" in lower or upercase ie avoid "private", "PRIVATE", "Private" ou "pRivATe" This seem to work fine : ^((?i)(?!private).(?-i))*$ I tried to combine both regex but cannot get it work ! By the way, I'm using extendsclass.com online tester. Thanks for help.

    JLO

    U 1 Reply Last reply
    0
    • U User 1567210

      Hello all, I'm a regex newbie and I'm stuck with regex in PCRE/PHP. First expression, I'd like to match letters, numbers or underscore but - no space at start or end - no more than one consecutive space This works fine : ^[\w]+([_\s]{1}[a-zA-Z0-9]+)*$ Second expression - no "private" in lower or upercase ie avoid "private", "PRIVATE", "Private" ou "pRivATe" This seem to work fine : ^((?i)(?!private).(?-i))*$ I tried to combine both regex but cannot get it work ! By the way, I'm using extendsclass.com online tester. Thanks for help.

      JLO

      U Offline
      U Offline
      User 1567210
      wrote on last edited by
      #2

      Finally after many trials, I think I found an answer : ^(?=((?i)(?!private).(?-i))*$)([\w]+([_\s]{1}[a-zA-Z0-9]+))*$ Bye

      J 1 Reply Last reply
      0
      • U User 1567210

        Finally after many trials, I think I found an answer : ^(?=((?i)(?!private).(?-i))*$)([\w]+([_\s]{1}[a-zA-Z0-9]+))*$ Bye

        J Offline
        J Offline
        jschell
        wrote on last edited by
        #3

        I didn't attempt to parse that but there seems to be several constructs in there that would make me nervous. You have two '$' and only one '^' It appears you have two optional clauses. Optional clauses without hard anchors general are always a problem because they likely make the regex engine do a lot of work. Since you already presumably have a working solution what makes you think you need to combine them into one expression? Or another way of saying that is that regexes use an iterative process to find the best solution and more complex expressions unless carefully crafted can cause unexpected problems (slowness.)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups