Hi ,
Great Monks of the Monastery ,please help on this
my $a = "x|xx|xx|xxxx|xx|xxx|xx|xx|x";
$a =~ s/x\|xx\|x/x\|x x\|x/g;
print "[$a]\n";
This gives the output
[x|x x|xx|xxxx|x x|xxx|x x|xx|x]
The string above has this pattern x|xx|x ,that has
to be changed to x|x x|x,( my intent is to change |xx| alone to |x x| and not any other occurances of xx )
when I am doing this , the
part of the code that has the pattern like x|xx|xx|x
is changed to x|x x|xx|x, I understand that when
the string is parsed and the pattern of x|xx|x occurs ,
it is changed to x|x x|x, but the next time when it
occurs together the parser would have crossed the
pattern and hence changes only the first occurance
and leaves the second one as it was in the string .
I am asking the way to recursively do pattern matching
or doing backtracking or something to match the second pattern as well
Alternately , a colleague had a while loop going
while($_ =~ s/x\|xx\|x/x\|x x\|x/g){
}
I have come to the monastery for an answer that will be in doing this recursively or through some other pattern to do this through regular expression itself
20030208 Edit by Corion - changed text from within code to normal text.
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.