Also check out re pragma , which will show how regular expressions are compiled and how they are executed:
$ perl -Mre=debugcolor -e '"huzza" =~ /^(hu)?z{1,2}za$/'
Exit:
Compiling REx "^ (hu)? Z {1,2} za $"
Final program:
1: BOL (2)
2: CURLYM [1] {0,1} (12)
6: EXACT (10)
10: SUCCEED (0)
11: NOTHING (12)
12: CURLY {1,2} (16)
14: EXACT (0)
16: EXACT (18)
18: EOL (19)
19: END (0)
floating "zza" $ at 0..3 (checking floating) anchored (BOL) minlen 3
Guessing start of match in sv for REx "^ (hu)? Z {1,2} za $" against "huzza"
Found floating substr "zza" $ at offset 2 ...
Guessed: match at offset 0
Matching REx "^ (hu)? Z {1,2} za $" against "huzza"
0 | 1: BOL (2)
0 | 2: CURLYM [1] {0,1} (12)
0 | 6: EXACT (10)
2 | 10: SUCCEED (0)
subpattern success ...
CURLYM now matched 1 times, len = 2 ...
CURLYM trying tail with matches = 1 ...
2 | 12: CURLY {1,2} (16)
EXACT can match 2 times out of 2 ...
3 | 16: EXACT (18)
5 | 18: EOL (19)
5 | 19: END (0)
Match successful!
Freeing REx: "^ (hu)? Z {1,2} za $"
Inshallah
source share