Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: regex backtracking question

by trizen (Hermit)
on Apr 24, 2014 at 10:59 UTC ( #1083562=note: print w/replies, xml ) Need Help??

in reply to regex backtracking question

You can think of any regular expression in term of some nested for loops.

Please, consider:
for my $i (0 .. $eos) { for my $j ($min .. $max) { last if $j > $eos-$i; print substr($str, $i, $j),"\n"; } }
The following variables specifies the meaning of "ABCDEF" =~ /(\w{2,}?)(?{print "$1\n"})(?!)/;
my $min = 2; # minimum match length my $max = 32767; # maximum match length my $str = "ABCDEF"; my $eos = length($str);

Using the same nested for loops, we have another specification for "ABCDEF" =~ /([A-Z]{3})(?{print "$1\n"})(?!)/;
my $min = 3; # minimum match length my $max = 3; # maximum match length my $str = "ABCDEF"; my $eos = length($str);

By executing the code, it gives us the same output as the corresponding regular expressions do. I hope this will give you a basic intuition on how backtracking works.

Replies are listed 'Best First'.
Re^2: regex backtracking question
by aeqr (Novice) on Apr 24, 2014 at 14:41 UTC
    Thanks for the additional info, I see why it is different now.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1083562]
[Corion]: Oof - "Anyway, if it is not obvious, please keep this discussion entirely confidential for now.", as seen on a public mailing list ;)
[Discipulus]: uh no choroba.. i do not practice much with online putyour image sites:can you suggest one (that possibly remove the pic after few days)?
[choroba]: Corion a bug report?
[choroba]: I have no idea :-( I used to post to, but they don't seem to feature "private" pictures in the free version now
[Discipulus]: dazz i'm not an experts but i think it would be possible
[Corion]: dazz: I think Image::Magick can "read" from an in-memory filehandle

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (9)
As of 2017-03-27 07:50 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (317 votes). Check out past polls.