> and I need to find the first occurrence of "+" that is not enclosed within parenthesis, i.e. the one before "5", how would I do that with a regular expression ?
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)
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.