in reply to Regex conditional match if previous match in same expression is true?
for ( 'oh {hello} there', 'oh {hello there', 'oh hello there', 'oh hello} there', ) { our $paren; if (/ ({ | (?<!{)) # optional opening brace (?{ $paren = $^N }) # store for later hello # .. followed by 'hello' (??{$paren ? "\}" : "(?!\})"}) # a closing brace if the open +brace was there /x) { print "Yep - $1\n"; } else { print "Nope\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regex conditional match if previous match in same expression is true?
by ikegami (Patriarch) on Apr 09, 2007 at 19:48 UTC | |
by demerphq (Chancellor) on Apr 10, 2007 at 17:30 UTC | |
by ikegami (Patriarch) on Apr 10, 2007 at 17:37 UTC |