RegExp - Retrieving an IP address

December 2016







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 :

This document entitled « RegExp - Retrieving an IP address » from CCM (ccm.net) is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the license, as this note appears clearly.