1

The output of my snmpwalk looks like this:

iso.3.6.1.2.1.4.20.1.2.10.0.1.2

The last four digits (in bold) are always an IP address. I cannot seem to create a regex that will give me just the IP address, ie 10.0.1.2

Any help is greatly appreciated! I suck at regex so if an explanation could be included, that would really help.

Vignesh Kumar A
  • 27,863
  • 13
  • 63
  • 115
cellis
  • 79
  • 6

2 Answers2

2

You can use match your ip address by regex

MatchIpAddressRegex = "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$";

Take a look at: http://answers.oreilly.com/topic/318-how-to-match-ipv4-addresses-with-regular-expressions/

Regular expression to match DNS hostname or IP Address?

http://www.regular-expressions.info/examples.html

Community
  • 1
  • 1
Vignesh Kumar A
  • 27,863
  • 13
  • 63
  • 115
1

You can just repeat it four times:

/(\d+\.\d+\.\d+\.\d+)$/

or shorter:

/(\d+(\.\d+){3})$/

See how it performs at Regex101

justhalf
  • 8,960
  • 3
  • 47
  • 74