Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Dynamically inspecting Regex OP-Codes at runtime?

by LanX (Canon)
on Jan 30, 2013 at 11:04 UTC ( #1016030=perlquestion: print w/ replies, xml ) Need Help??
LanX has asked for the wisdom of the Perl Monks concerning the following question:

Hi

ATM I need plenty of hacks to be able to dynamically see the OP-Tree of a Regex at runtime cause use re 'debug' emits the code of a regex at compile time to STDERR.

lanx@nc10-ubuntu:~$ perl use re 'debug'; my $a=qr/(?<C>1)(?<D>2)(3)(?<A>4)/; Compiling REx "(?<C>1)(?<D>2)(3)(?<A>4)" Final program: 1: OPEN1 'C' (3) 3: EXACT <1> (5) 5: CLOSE1 'C' (7) 7: OPEN2 'D' (9) 9: EXACT <2> (11) 11: CLOSE2 'D' (13) 13: OPEN3 (15) 15: EXACT <3> (17) 17: CLOSE3 (19) 19: OPEN4 'A' (21) 21: EXACT <4> (23) 23: CLOSE4 'A' (25) 25: END (0) anchored "1234" at 0 (checking anchored) minlen 4 Freeing REx: "(?<C>1)(?<D>2)(3)(?<A>4)"

In Re^2: Is there really no @LAST_MATCH_START equivalent for named capture groups? I need to recompile a new regex within an eval while redirecting STDERR to a variable...

Thats hacky and cumbersome!

Is there any simpler or cleaner way to achieve this?

Cheers Rolf

Comment on Dynamically inspecting Regex OP-Codes at runtime?
Select or Download Code
Replies are listed 'Best First'.
Re: Dynamically inspecting Regex OP-Codes at runtime?
by Anonymous Monk on Jan 30, 2013 at 11:37 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1016030]
Approved by Corion
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (8)
As of 2015-07-31 04:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (274 votes), past polls