in reply to extracting variables from regex
But if you recast your regex slightly, you can get SOME information.
With a quantifier, a capturing paren shows the last element matched. But by adding another set of parens AROUND the quantifier, you can get the "grouped match".
(Edit:You're better off using the other approaches suggested in the other responses, though)/(\d\.?){1,4}/ # $1 is last octet matched /((\d\.?){1,4})/ # $1 is IP address, $2 is last octet matched
Not really useful in this case, I admit, but then again, for your academic case all you really needed was a call to split :)
(Edit:Juerd is right, I should have used the split in list context)echo 1234.45.67.890 | perl -ne'printf "%X%X%X%X",split /\./'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: extracting variables from regex
by Juerd (Abbot) on Apr 02, 2002 at 22:05 UTC | |
by MeowChow (Vicar) on Apr 03, 2002 at 12:01 UTC | |
by RMGir (Prior) on Apr 02, 2002 at 22:17 UTC |