IP /24 Range Regular Expression

Example: 192.168.15.0/24

Range: 192.168.15.1 – 192.168.15.254

Regexp: ^192\.168\.15\.([1-9]|[1-9][0-9]|1([0-9][0-9])|2([0-4][0-9]|5[0-4]))$

Check:

  • ^ assert position at start of the string
  • 192 matches the characters 192 literally
  • \. matches the character . literally
  • 168 matches the characters 168 literally
  • \. matches the character . literally
  • 15 matches the characters 15 literally
  • \. matches the character . literally
  •  1st Capturing group ([1-9]|[1-9][0-9]|1([0-9][0-9])|2([0-4][0-9]|5[0-4]))
    • 1st Alternative: [1-9]
      • [1-9] match a single character present in the list below
        • 1-9 a single character in the range between 1 and 9
    •  2nd Alternative: [1-9][0-9]
      • [1-9] match a single character present in the list below
        • 1-9 a single character in the range between 1 and 9
      • [0-9] match a single character present in the list below
        • 0-9 a single character in the range between 0 and 9
    •  3rd Alternative: 1([0-9][0-9])
      • 1 matches the character 1 literally
      • 2nd Capturing group ([0-9][0-9])
        • [0-9] match a single character present in the list below
          • 0-9 a single character in the range between 0 and 9
        • [0-9] match a single character present in the list below
          • 0-9 a single character in the range between 0 and 9
    •  4th Alternative: 2([0-4][0-9]|5[0-4])
      • 2 matches the character 2 literally
      • 3rd Capturing group ([0-4][0-9]|5[0-4])
        • 1st Alternative: [0-4][0-9]
          • [0-4] match a single character present in the list below
            • 0-4 a single character in the range between 0 and 4
          • [0-9] match a single character present in the list below
            • 0-9 a single character in the range between 0 and 9
        •  2nd Alternative: 5[0-4]
          • 5 matches the character 5 literally
          • [0-4] match a single character present in the list below
            • 0-4 a single character in the range between 0 and 4
  • $ assert position at end of the string

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s