in reply to Regex replace in context

It does indeed mean you canīt have quantifiers in the lookbehind. It's mostly useful for single-character assertions or fixed tokens. It's also more useful in a simple match rather than a substitution.

Makeshifts last the longest.

Replies are listed 'Best First'.
Re: Re: Regex replace in context
by John M. Dlugosz (Monsignor) on Dec 11, 2002 at 21:18 UTC
    It's also more useful in a simple match rather than a substitution.

    I don't see it. "Find a b only if its following an a" is just a normal search! If /ab/ matches (I'm only interested in "did it?", then /b/ must also be true. I don't need to dress it up at all. Or, if the starting position is what's important, then /a\Gb/ I think.

      I don't have a good example off hand, but it's more interesting toward the end of a complex variable pattern (esp with /g ) where you just want to exclude a few fringe conditions without extraordinarily complicating the rest of the match. Granted, it doesn't get much use - I think I needed it twice ever maybe - but it's nifty to have around if it doesn't add much weight.

      Makeshifts last the longest.

      True, but if you have a regex of the type "a pattern" followed by "another pattern which might contain the first pattern" and you want to find all occurrences, you have to use the look forward assertion or otherwise you have "used up" the second pattern and you will miss it.

      CountZero

      "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law