#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Posts
    4
    Rep Power
    0

    Regexp Difficulties


    Hi. I want to match a string with a regexp patter similar to:

    '/X(not foo|bar)X/'

    Basically, it would match anything except 'XfooX' and 'XbarX'.

    The closest pattern I can come up with is '/X[^(foo|bar)]X/'.

    This, however, doesn't work because ()'s lose their "special powers" within []'s. Is there any simple way to do this? And if there's no simple way, what would be the complex way?

    EDIT: Wait a minute... I guess I actually posted incorrectly. Sorry about that... I would want it to match strings such as 'XasdfX' and 'XffffffffffffffffX' and 'XzxbcvasdfaX'. I just don't want it to match the string if it has 'foo' or 'bar' in the middle of the X's. In fact, I would also like it to match 'foo XasdfX bar'.
    Last edited by douceur; May 6th, 2003 at 06:54 PM.
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Location
    Mexico
    Posts
    116
    Rep Power
    12
    How about making 2 different checks?

    IF

    Match 'X(foo|bar)X'

    OUT

    ELSEIF

    Match 'X([a-zA-Z])X'

    IN

    ELSE

    OUT
    The best way to learn is:
    read + try + ask (in that order)

    Manolo
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Posts
    4
    Rep Power
    0
    Thanks for the help, though I believe that my problem has been solved by somebody on a different message board:

    /X(?!fooX|barX)X/

IMN logo majestic logo threadwatch logo seochat tools logo