in reply to lookbehind

that particular part of Mastering Regular Expressions is out of date and no longer correct. if i recall correctly, MRE is written against 5.004 and lookbehind was added to 5.005.

the lookbehind syntax is as follows:

0-width positive lookbehind assertion: (?<=pattern)
0-width negative lookbehind assertion: (?<!pattern)

however, i think what you want in this case is actually a negative lookahead assertion like the following:

m!^<TR bgcolor=.*>(?!(?:re:\s*)+)([^<]*)</a>!i

also, the 'o' modifier is not very useful in your examples, since there are no variables in the regexp to interpolate.

Replies are listed 'Best First'.
RE: Re: lookbehind
by httptech (Chaplain) on May 07, 2000 at 22:56 UTC
    I'm a little confused... I thought the "o" modifier was used only when you have no variables to interpolate. Doesn't it tell Perl to compile the regex one time instead of every time it's evalutated, thus speeding up the program? Please clarify the role of "o" because I must have missed something important.
      since a regular expression without variable interpolation doesn't have the potential to change between uses, Perl only ever compiles it once. however, when a regular expression contains a variable to be interpolated, the value of the variable can potentially be different every time, so Perl compiles the regular expression with the current value of the variable every time it is used. the 'o' modifier tells Perl that the values of interpolated variables should be treated as constant, so that Perl will only compile the regular expression 'once' no matter how many times you use it.

      i'm not sure whether or not using 'o' on a regexp without any variable interpolation adversely affects performance, but it is simply unnecessary.

        Great explanation, thanks! I'm sure this point has confused others in the past, because I've seen more experienced Perl programmers than me make the same mistake (probably where I picked it up from).