Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Dynamically inspecting Regex OP-Codes at runtime?

by LanX (Bishop)
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:


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

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?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1016030]
Approved by Corion
Front-paged by Arunbear
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (9)
As of 2018-06-19 15:21 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (114 votes). Check out past polls.