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

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

by LanX (Chancellor)
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 the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2016-06-27 23:10 GMT
Find Nodes?
    Voting Booth?
    My preferred method of making French fries (chips) is in a ...

    Results (347 votes). Check out past polls.