Beefy Boxes and Bandwidth Generously Provided by pair Networks BBQ
Problems? Is your data what you think it is?
 
PerlMonks  

Regular Expression Debugger ?

by John M. Dlugosz (Monsignor)
on Nov 15, 2001 at 22:31 UTC ( [id://125720]=perlquestion: 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.

John M. Dlugosz has asked for the wisdom of the Perl Monks concerning the following question:

I know I've seen discussion of such a beast, but Super Search on the title phrase didn't find anything. Anybody know?

A friend of mine is interested in learning R.E. and I remembered hearing about that.

—John

Replies are listed 'Best First'.
(Ovid) Re: Regular Expression Debugger ?
by Ovid (Cardinal) on Nov 15, 2001 at 22:41 UTC

    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.

Re: Regular Expression Debugger ?
by LD2 (Curate) on Nov 15, 2001 at 22:56 UTC
Re: Regular Expression Debugger ?
by RhetTbull (Curate) on Nov 16, 2001 at 01:24 UTC
    While not really a debugger, I'm partial to japhy's excellent YAPE::Regex::Explain which does a great job explaining regex's in plain English.

    -RT

Re: Regular Expression Debugger ?
by Fletch (Bishop) on Nov 16, 2001 at 03:02 UTC
Re: Regular Expression Debugger ?
by dvergin (Monsignor) on Nov 16, 2001 at 03:18 UTC
    The Komodo programming environment from ActiveState includes a very interesting dynamic regex debugging feature. You can do things like: tweak the regex and the highlighting in your test strings changes to show what will be matched, etc.

      Which is based on Rx. Dominus wrote an excellent paper on the development of Rx. It won a "best paper" award at The Perl Conference this year. It's included in the proceedings of the conference or on his web site.

      --
      <http://www.dave.org.uk>

      "The first rule of Perl club is you don't talk about Perl club."

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://125720]
Approved by root
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.