Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: How do I extract named variable names from regex string

by LanX (Bishop)
on Jan 31, 2012 at 00:04 UTC ( #950849=note: print w/replies, xml ) Need Help??

in reply to How do I extract named variable names from regex string

I'm too lazy to work out a complete solution but a clean approach would be to deparse the regex-compilation:

> perl -e 'use re 'debug';/(?i-xsm:(?<mon>\w+)\s+(?<day>\d+)\s+)/' Compiling REx "(?i-xsm:(?<mon>\w+)\s+(?<day>\d+)\s+)" Final program: 1: OPEN1 'mon' (3) 3: PLUS (5) 4: ALNUM (0) 5: CLOSE1 'mon' (7) 7: PLUS (9) 8: SPACE (0) 9: OPEN2 'day' (11) 11: PLUS (13) 12: DIGIT (0) 13: CLOSE2 'day' (15) 15: PLUS (17) 16: SPACE (0) 17: END (0) stclass ALNUM plus minlen 4 Freeing REx: "(?i-xsm:(?<mon>\w+)\s+(?<day>\d+)\s+)"

Now fetching all /OPEN\d+ '(\w+)'/-opcodes shouldn't be too difficult.

See perldoc re for more options.

Cheers Rolf

UPDATE: shrank example.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://950849]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2018-02-25 12:08 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (312 votes). Check out past polls.