Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
Do you know where your variables are?
 
PerlMonks  

(Ovid) Re: Regular Expression Debugger ?

by Ovid (Cardinal)
on Nov 15, 2001 at 22:41 UTC ( [id://125724]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Regular Expression Debugger ?

Try this snippet:

#!/usr/bin/perl -w use strict; use re 'debug'; my $test = "abc123abc1234abc"; $test =~ /(\d{4})/; print $1;

The output from that is:

Compiling REx `(\d{4})' size 8 first at 5 1: OPEN1(3) 3: CURLY {4,4}(6) 5: DIGIT(0) 6: CLOSE1(8) 8: END(0) stclass `DIGIT' minlen 4 Matching REx `(\d{4})' against `abc123abc1234abc' Setting an EVAL scope, savestack=5 3 <abc> <123abc123> | 1: OPEN1 3 <abc> <123abc123> | 3: CURLY {4,4} DIGIT can match 3 times out of 4... Setting an EVAL scope, savestack=5 failed... Setting an EVAL scope, savestack=5 4 <abc1> <23abc123> | 1: OPEN1 4 <abc1> <23abc123> | 3: CURLY {4,4} DIGIT can match 2 times out of 4... Setting an EVAL scope, savestack=5 failed... Setting an EVAL scope, savestack=5 5 <abc12> <3abc123> | 1: OPEN1 5 <abc12> <3abc123> | 3: CURLY {4,4} DIGIT can match 1 times out of 4... Setting an EVAL scope, savestack=5 failed... Setting an EVAL scope, savestack=5 9 <23abc> <1234abc> | 1: OPEN1 9 <23abc> <1234abc> | 3: CURLY {4,4} DIGIT can match 4 times out of 4... Setting an EVAL scope, savestack=5 13 <23abc1234> <abc> | 6: CLOSE1 13 <23abc1234> <abc> | 8: END Match successful! 1234Freeing REx: `(\d{4})'

It's fairly complicated, but if you really need to get into the guts of how regular expressions work, that should do it.

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://125724]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.