2

I've turned on case insensitivity...

I want to match abc anywhere except in watch?v=xxabcxx or tumblr_asdfabcasdf.

But if I use (watch\?v=[0-9a-zA-Z]){0}abc against watch?v=xxabcxx, it matches, presumably because the engine fails until it checks abcxxx which is fine.

Hypershadsy
  • 398
  • 4
  • 13

1 Answers1

1

In regular expressions that is called negative look behind (also ahead, depending of the direction you need to look at). Check the tutorial on "Positive and Negative Lookahead".

You might want also check the question and answer for "Regular expression negative lookahead".

As an example, take a look at (watch\?v=.*)(?<!xx)abc, the part (?<xx)abc can be read as abc matches only if the preceding letters do not match with xx, where (?a)b is the format to put a condition a before apply b. Also, the symbol < says look behind and the exclamation mark ! is to negate the condition. I used a generic regular expression, but you can get the idea.

Community
  • 1
  • 1
gpoo
  • 8,408
  • 3
  • 38
  • 53