Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: regex question/mystery

by brian_d_foy (Abbot)
on Jan 17, 2006 at 18:39 UTC ( #523798=note: print w/replies, xml ) Need Help??


in reply to regex question/mystery

Do you mean that $1 is set and $2 isn't if you find ifSpeed, but it's the other way around for the 1.3.6...?

To make things simple, Perl assigns the memory variables based on the order of the opening parentheses. You don't have to worry about match order or nesting that way.

Perhaps you wanted this regular expression that only has one thing to remember:

/^(?:ifSpeed.|1.3.6.1.2.1.2.2.1.5.)(\d+)/

The first group of parentheses uses ?: to tell Perl they are just for grouping (so no memory variable). That way, the alternation is a single unit and the stuff that comes after either prefix shows up in $1.

--
brian d foy <brian@stonehenge.com>
Subscribe to The Perl Review

Replies are listed 'Best First'.
Re^2: regex question/mystery
by Anonymous Monk on Jan 17, 2006 at 18:45 UTC
    Thats exactly what I needed, and thanks for the explanation.

    I'm always learning!
    Thanks again!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://523798]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2020-05-25 02:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If programming languages were movie genres, Perl would be:















    Results (143 votes). Check out past polls.

    Notices?