in reply to Regex: first match that is not enclosed in parenthesis
depends what you mean with "finding"!
If it's just the position you need, a simple technique I like is to replace all inner paren-pairs till you get a "cleaned" string and then to try finding whatever it needs.
This demonstrates the intermediate results:
DB<172> $s=$s0 => "1*((2+3)*((3+4)+5))*(6+7)+8" DB<173> print "$s\n" while $s =~ s# \( [^()]* \) # '.' x length($&) +#gex 1*(.....*(.....+5))*.....+8 1*(.....*.........)*.....+8 1*.................*.....+8 DB<174> index $s, '+' => 25
Cheers Rolf
( addicted to the Perl Programming Language)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regex: first match that is not enclosed in parenthesis
by monkprentice (Novice) on Jun 30, 2013 at 13:53 UTC | |
by hdb (Monsignor) on Jun 30, 2013 at 16:53 UTC | |
by LanX (Saint) on Jun 30, 2013 at 16:23 UTC |