Shawn wrote: > > So, I have an interesting question and a bit of code. I didn't really > know whether this was the right forum or not, but here goes. > > I have two goals I would like help with: > 1. Optimize/simplify the regex > 2. Recognize where the regex would produce false positives on some > ifDescrs which don't actually have a real hardware path > > Really, #1 is most befitting this mailing list, but if anyone wants to > help with #2 that's great. > > For those of you who are famimliar, a cisco router's SNMP ifDescr can > contain what i would describe as the hardware path of whatever interface > you are querying. For example, "Ethernet1/0", "T3 3/0/2", "POS2/0/1". > Juniper routers have a similar thing. > > Now, I have the following regex to split these up into four pieces. > /^([^0-9]+)([0-9]+ |)([0-9]+\/[^\s]+)(.*)$/ > $1 : Is a required match of some non-numeric chars. This would > match "Ethernet", or the "T" in T3 or T1 > $2 : An optional match which would catch the "3 " in ifDescrs > like "T3 3/0/1" > $3 : string starting with one or more numerics, then a "/", then > all non-whitespace > $4 : the rest > > In all cases I've seen, the text before the hardware path will only end > in a numeric char if there is a space terminating it. Hence, "T3 3/0/2" > returning $3 == "3/0/2" and "Ethernet0/1" returning $3 == "0/1". > > Now, can anyone see how the regex could be simplified?
You can use \d instead of [0-9], \D instead of [^0-9] and \S instead of [^\s]. /^(\D+)(\d+ |)(\d+\/\S+)(.*)$/ John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]