[NCLUG] regex for snmp
mike cullerton
michaelc at cullerton.com
Wed Nov 21 08:57:11 MST 2001
hey folks,
hope everyone is having a great week. thanksgiving is my favorite holiday.
there's no avoiding it, this one is definitely about the food!
anyway, i'm reinventing the wheel here, writing some little functions to
help with snmp calls and i'm having some regex trouble. i'm trying to parse
the results i get from an snmpwalk and break it up into the individual MIB
elements. the output i receive is just one big long string.
so, i would like to break up
system.sysName.0 = gw system.sysLocation.0 = fort collins
into
system.sysName.0 = gw
system.sysLocation.0 = fort collins
these are easy, and my regex works for them, but here's the tough one...
system.sysDescr.0 = Cisco Internetwork Operating System Software
IOS (tm) 2500 Software (C2500-I-L), Version 11.2(23), RELEASE SOFTWARE (fc1)
Copyright (c) 1986-2000 by cisco Systems, Inc.
Compiled Thu 06-Jul-00 14:24 by torowe
with this one, my regex only grabs "Cisco Internetwork Operating System
Software".
my regex is pretty lame, i think, but it's a start. anyone with some
suggestions for fixing it. (this is a perl regex, but i would take a posix
answer as well)
/[\S]+ = .*\s/
the left side (before the ' = ') is always a bunch of letters and digits
separated by periods. it appears there is always a space before the 'next
element' so, what i'd like to have, is something like
/[[a-zA-Z0-9]+\.]+[a-zA-Z0-9]+ = .*\s/
can you even nest brackets like that? it doesn't appear so :)
thanks folks,
happy thanksgiving,
mike
-- mike cullerton michaelc at cullerton dot com
More information about the NCLUG
mailing list