http://qs1969.pair.com?node_id=523798


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