Pattern: IPv4 Address

“IPv4 address” is one of the patterns that you can select on the Match panel. Use it to make a field match an internet address such as 192.168.0.1.

The documentation for Google Analytics explains how you can use a regular expression in Google Analytics to filter on IP addresses. We’ll follow the same example here, but explain how to generate the regular expression with RegexMagic.

  1. Click the New Formula button on the top toolbar to clear out all settings on the Samples, Match, and Action panels.
  2. On the Samples panel, paste in one new sample:
    10.1.1.1
    10.255.255.254
    172.0.0.1
    172.16.0.1
    172.31.255.254
    172.255.255.254
    192.168.1.1
    192.168.255.254
    63.212.171.1
    63.212.171.254
    8.8.8.8
    8.8.4.4
    
  3. Set the subject scope to “line by line”.
  4. On the Match panel, set “begin regex match at” to “start of text”, and set “end regex match at” to “end of text”.
  5. Click the Add First Field button to add field 1.
  6. In the “pattern to match field” drop-down list, select “IPv4 address”. By default, this pattern matches any IPv4 address in dotted notation.



  7. Turn on “limit the IPv4 addresses to these ranges”.
  8. Enter 63.212.171.1..63.212.171.254 as the range to limit the IP addresses to.
  9. Set the “field validation mode” to “strict”. This is necessary to make RegexMagic limit the range of IP addresses to exactly what you specified.
  10. On the Regex panel, select “POSIX ERE” as your application. This is a basic regular expression flavor which ensures your regex will be compatible with most log analysis tools. It does not support free-spacing or mode modifiers, so those options are forced off. Click the Generate button, and you’ll get this regular expression:
    ^63\.212\.171\.(25[0-4]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)$
    Required options: ^$ don’t match at line breaks; dot matches line breaks.
    Unused options: Case sensitive.
  11. The Samples panel now highlights the IP addresses in the range that we specified:
    10.1.1.1
    10.255.255.254
    172.0.0.1
    172.16.0.1
    172.31.255.254
    172.255.255.254
    192.168.1.1
    192.168.255.254
    63.212.171.1
    63.212.171.254
    8.8.8.8
    8.8.4.4
    

Related Examples

Reference