in reply to Re: Regex replace in context
in thread Regex replace in context

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.

Replies are listed 'Best First'.
Re^3: Regex replace in context
by Aristotle (Chancellor) on Dec 11, 2002 at 21:55 UTC
    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.

Re: Re: Re: Regex replace in context
by CountZero (Bishop) on Dec 11, 2002 at 22:52 UTC

    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