2

I am trying this regex

(?<!(John|Joe)) (Taylor)

On this text John James Taylor

but I am getting "invalid pattern in lookbehind" here http://www.rubular.com/r/TjD2d4oG5z

I am trying to match "Taylor" that does not have John or Joe before it.

Any tips please?

giorgio79
  • 3,787
  • 9
  • 53
  • 85
  • 2
    Is your regex flavor accept variable length lookbehind? Most of them don't. – Toto Sep 24 '12 at 09:58
  • Thanks! Just found out that variable length does not work in lookaround by this comment: http://stackoverflow.com/questions/3479131/problem-with-quantifiers-and-look-behind In addition both of the answers are working with the proposed changes, but not if I add sg like \w+ because that is a variable length quantifier as I understand now :). – giorgio79 Sep 24 '12 at 10:02

2 Answers2

3

Try the following:

(?<!(?:John|Joe)) (Taylor)

(?:) is a non-capturing group, which makes sense in a lookaround, since you are merely doing an assertion, not actually matching anything. Or just remove the capturing group all together, that is, (?<!John|Joe).

João Silva
  • 89,303
  • 29
  • 152
  • 158
2

Try:

/(?<!John|Joe) (Taylor)/
xdazz
  • 158,678
  • 38
  • 247
  • 274