in reply to Re^2: Regex conditional match if previous match in same expression is true?
in thread Regex conditional match if previous match in same expression is true?
can you think of a solution that uses the conditional notation
The algorithm:
As it turns out, the "if any" portion of the first step is hard to implement because look-behinds must be fixed-width. So let's make that conditional too:
/ (?(?<=(.)) # We are not at the start of the string. # The preceding character is in $1. hello (?(?{ $1 eq "\{" }) # The char before 'hello' is '{'. } | # The char before 'hello' is not '{'. (?! } ) ) | # We are at the start of the string. hello (?! } ) ) /x
Yikes!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Regex conditional match if previous match in same expression is true?
by radiantmatrix (Parson) on Apr 10, 2007 at 15:55 UTC | |
by ikegami (Patriarch) on Apr 10, 2007 at 16:23 UTC | |
by radiantmatrix (Parson) on Apr 23, 2007 at 14:25 UTC |