RegExp - Retrieving an IP address

March 2017







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.

Related


Published by netty5.
This document, titled "RegExp - Retrieving an IP address," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (ccm.net).