#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2010
    Posts
    2
    Rep Power
    0

    Unhappy Find soccer, unless play.{0,5} soccer


    Hey
    In a single perl regex I want to catch any occurrence of "soccer" in a sentence, unless it is preceded by "play/played/playing".

    In other words, I would want to catch
    Code:
    .*_soccer_.*
    but not

    Code:
    .*(play|played|playing)_soccer_.*
    (underscore_represents_spaces)

    I tried
    Code:
    .*(?<!play|played|playing)_soccer_.*
    But the regex failed because perl does not support variable-length-lookbehind...

    Are there any working ways to do this?
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,113
    Rep Power
    9398
    Pretty sure you can work around it with
    Code:
    (?<!play )(?<!played )(?<!playing )\bsoccer\b
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2010
    Posts
    2
    Rep Power
    0

    I found an amazing way to do it


    Looks like a good call!

    But I found an even better method, which allows me to use some more tricks to make the searching even more precise:

    Code:
    ^(?!.*play.{0,9}soccer).*s[ou0]+c+er
    This way I can get "succer" and "play succer", but still not catch "play soccer".

    Thank you!

IMN logo majestic logo threadwatch logo seochat tools logo