Regular Expressions 101

Save & Share

Flavor

  • PCRE2 (PHP >=7.3)
  • PCRE (PHP <7.3)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java 8

Function

  • Match
  • Substitution
  • List
  • Unit Tests
"
^((?:[0-9]{1,3}\.){3}[0-9]{1,3})\n((?:.*\s)*)(?=\n)
"
^ asserts position at start of the string
1st Capturing Group
((?:[0-9]{1,3}\.){3}[0-9]{1,3})
Non-capturing group
(?:[0-9]{1,3}\.){3}
{3} matches the previous token exactly 3 times
Match a single character present in the list below
[0-9]
{1,3} matches the previous token between 1 and 3 times, as many times as possible, giving back as needed (greedy)
0-9 matches a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)
\. matches the character . with index 4610 (2E16 or 568) literally (case sensitive)
Match a single character present in the list below
[0-9]
{1,3} matches the previous token between 1 and 3 times, as many times as possible, giving back as needed (greedy)
0-9 matches a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)
\n matches a line-feed (newline) character (ASCII 10)
2nd Capturing Group
((?:.*\s)*)
Non-capturing group
(?:.*\s)*
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
.
matches any character (except for line terminators)
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
\s matches any whitespace character (equivalent to [\r\n\t\f\v  ])
Positive Lookahead
(?=\n)
Assert that the Regex below matches
\n matches a line-feed (newline) character (ASCII 10)
Your regular expression does not match the subject string.

Regular Expression
No Match

r"
"

Test String