K
Krishna Chaitanya
Hi, am trying out the "Smeagol" example from "Programming
Perl" (section 5.9.3) :
#!/usr/bin/perl
use re "debug";
"Smeagol" =~ /^Sm(.*)g[aeiou]l$/;
Am using perl 5.10.0 on 32-bit Windows XP. Following is the output:
====================================
Compiling REx "^Sm(.*)g[aeiou]l$"
Final program:
1: BOL (2)
2: EXACT <Sm> (4)
4: OPEN1 (6)
6: STAR (8)
7: REG_ANY (0)
8: CLOSE1 (10)
10: EXACT <g> (12)
12: ANYOF[aeiou] (23)
23: EXACT <l> (25)
25: EOL (26)
26: END (0)
anchored "Sm" at 0 floating "l"$ at 4..2147483647 (checking anchored)
anchored(BOL) minlen 5
Guessing start of match in sv for REx "^Sm(.*)g[aeiou]l$" against
"Smeagol"
Guessed: match at offset 0
Matching REx "^Sm(.*)g[aeiou]l$" against "Smeagol"
0 <> <Smeagol> | 1:BOL(2)
0 <> <Smeagol> | 2:EXACT <Sm>(4)
2 <Sm> <eagol> | 4:OPEN1(6)
2 <Sm> <eagol> | 6:STAR(8)
REG_ANY can match 5 times out of
2147483647...
4 <Smea> <gol> | 8: CLOSE1(10)
4 <Smea> <gol> | 10: EXACT <g>(12)
5 <Smeag> <ol> | 12: ANYOF[aeiou](23)
6 <Smeago> <l> | 23: EXACT <l>(25)
7 <Smeagol> <> | 25: EOL(26)
7 <Smeagol> <> | 26: END(0)
Match successful!
Freeing REx: "^Sm(.*)g[aeiou]l$"
====================================
Why is there no backtracking for the maximal match quantifier " * "?
Or backtracking is actually happening but the pragma re "debug" output
is different (not showing backtracking)? Could someone please point
out if I'm missing anything?
Thanks
Perl" (section 5.9.3) :
#!/usr/bin/perl
use re "debug";
"Smeagol" =~ /^Sm(.*)g[aeiou]l$/;
Am using perl 5.10.0 on 32-bit Windows XP. Following is the output:
====================================
Compiling REx "^Sm(.*)g[aeiou]l$"
Final program:
1: BOL (2)
2: EXACT <Sm> (4)
4: OPEN1 (6)
6: STAR (8)
7: REG_ANY (0)
8: CLOSE1 (10)
10: EXACT <g> (12)
12: ANYOF[aeiou] (23)
23: EXACT <l> (25)
25: EOL (26)
26: END (0)
anchored "Sm" at 0 floating "l"$ at 4..2147483647 (checking anchored)
anchored(BOL) minlen 5
Guessing start of match in sv for REx "^Sm(.*)g[aeiou]l$" against
"Smeagol"
Guessed: match at offset 0
Matching REx "^Sm(.*)g[aeiou]l$" against "Smeagol"
0 <> <Smeagol> | 1:BOL(2)
0 <> <Smeagol> | 2:EXACT <Sm>(4)
2 <Sm> <eagol> | 4:OPEN1(6)
2 <Sm> <eagol> | 6:STAR(8)
REG_ANY can match 5 times out of
2147483647...
4 <Smea> <gol> | 8: CLOSE1(10)
4 <Smea> <gol> | 10: EXACT <g>(12)
5 <Smeag> <ol> | 12: ANYOF[aeiou](23)
6 <Smeago> <l> | 23: EXACT <l>(25)
7 <Smeagol> <> | 25: EOL(26)
7 <Smeagol> <> | 26: END(0)
Match successful!
Freeing REx: "^Sm(.*)g[aeiou]l$"
====================================
Why is there no backtracking for the maximal match quantifier " * "?
Or backtracking is actually happening but the pragma re "debug" output
is different (not showing backtracking)? Could someone please point
out if I'm missing anything?
Thanks