Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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.


In reply to A complex recursive regex,help by OM_Zen

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2024-04-20 03:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found