Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Regex Backtracking

by frankus (Priest)
on Jun 12, 2002 at 17:00 UTC ( #173931=note: print w/replies, xml ) Need Help??


in reply to Regex Backtracking

What is happening is as it stands the regular expression is evaluating two characters at a time.Whereas the frame for the matches should be one character. A sloppy fix would be:
while (<DATA>) {
   $i=0 while s/\|\|/\| \|/g; # repeats as many times as is necessary
   print;  
}
As joost rightly says the forward lookahead operation is probably the best way to go.
To make regexes easier to read try using the debug pragma:

use re 'debugcolor'

To get insight into how the regexes do what they do ;)

I'd love to find a solution using the 'c' modifier .. but then I'm not Abigail

--

Brother Frankus.

¤

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://173931]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2016-12-09 15:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (152 votes). Check out past polls.