in reply to Re^3: Search for consecutive flush left curly braces
in thread Search for consecutive flush left curly braces
OK, you’re wrong. SCNR. :-)
First off, for the reason given by QM, this regex doesn’t prevent a match if there is a { character between } characters:
2:57 >perl -wE "my $s = '}abc{def}'; say 'match' if $s =~ /}.*(?!{)}/ +;" match 2:59 >
Second, there is no non-greedy match here: .* is greedy. But making it non-greedy doesn’t help:
2:59 >perl -wE "my $s = '}abc{def}'; say 'match' if $s =~ /}.*?(?!{)} +/;" match 2:59 >
A negated character class is what is needed:
3:31 >perl -wE "my $s = '}abc{def}'; say 'match' if $s =~ /}[^{]*?}/; +" 3:31 >perl -wE "my $s = '}abc|def}'; say 'match' if $s =~ /}[^{]*?}/; +" match 3:31 >
Hope that helps,
Update: Tweaked the third code snippet.
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Search for consecutive flush left curly braces
by stevieb (Canon) on Jun 10, 2015 at 17:54 UTC |