Regular Expressions 101

Task 7: Validate an IP [44 chars, Non-Optimal]

Open Workspace
  • PCRE2 (PHP)
  • Match
2

Regular Expression

/
^(?:(?:1?\d?\d|2[0-4]\d|25[0-5])\.?\b){4}$
/
mg

Description

Near-optimal solution for Task 7 https://regex101.com/quiz/7 . Optimal is 39 characters.

Credit to Danail Gabenski on stackoverflow for the \.\b trick.

Submitted by chakra