Para obtener información sobre la forma en que es compilada una expresión regular
y como se produce el proceso de matching podemos usar la opción
'debug'
del módulo re
. La versión de Perl 5.10 da una información
algo mas legible que la de las versiones anteriores:
pl@nereida:~/Lperltesting$ perl5_10_1 -wde 0 Loading DB routines from perl5db.pl version 1.32 Editor support available. Enter h or `h h' for help, or `man perldebug' for more help. main::(-e:1): 0 DB<1> use re 'debug'; 'astr' =~ m{[sf].r} Compiling REx "[sf].r" Final program: 1: ANYOF[fs][] (12) 12: REG_ANY (13) 13: EXACT <r> (15) 15: END (0) anchored "r" at 2 (checking anchored) stclass ANYOF[fs][] minlen 3 Guessing start of match in sv for REx "[sf].r" against "astr" Found anchored substr "r" at offset 3... Starting position does not contradict /^/m... start_shift: 2 check_at: 3 s: 1 endpos: 2 Does not contradict STCLASS... Guessed: match at offset 1 Matching REx "[sf].r" against "str" 1 <a> <str> | 1:ANYOF[fs][](12) 2 <as> <tr> | 12:REG_ANY(13) 3 <ast> <r> | 13:EXACT <r>(15) 4 <astr> <> | 15:END(0) Match successful! Freeing REx: "[sf].r"
Si se usa la opción debug
de re
con
objetos expresión regular, se obtendrá información durante el proceso de
matching:
DB<3> use re 'debug'; $re = qr{[sf].r} Compiling REx "[sf].r" Final program: 1: ANYOF[fs][] (12) 12: REG_ANY (13) 13: EXACT <r> (15) 15: END (0) anchored "r" at 2 (checking anchored) stclass ANYOF[fs][] minlen 3 DB<4> 'astr' =~ $re Guessing start of match in sv for REx "[sf].r" against "astr" Found anchored substr "r" at offset 3... Starting position does not contradict /^/m... start_shift: 2 check_at: 3 s: 1 endpos: 2 Does not contradict STCLASS... Guessed: match at offset 1 Matching REx "[sf].r" against "str" 1 <a> <str> | 1:ANYOF[fs][](12) 2 <as> <tr> | 12:REG_ANY(13) 3 <ast> <r> | 13:EXACT <r>(15) 4 <astr> <> | 15:END(0) Match successful!