[RegExp]Retrieving an IP address

Last update on July 6, 2009 08:23 AM by jak58
Published by netty5

[RegExp]Retrieving an IP address







Purpose


Recovering an IP address from text file, log files, web pages, etc.

Implementation


The following regular expression combined with a specific command (grep, sed, etc.) should be enough :
([0-9]{1,3}\.){3}[0-9]{1,3}

Explanations


Interpretation of the pattern

([0-9]{1,3}\.){3} : a sequence of one to three digits followed by a point, all repeated three times.
[0-9] (1,3): a number made of one to three digits.