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
/
^[^\t\n]*\t(?P<host_ip>[^\t]+)[^\t\n]*\t(?P<username>[a-z]+_[a-z]+)
/
^ asserts position at start of the string
Match a single character not present in the list below
[^\t\n]
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
\t matches a tab character (ASCII 9)
\n matches a line-feed (newline) character (ASCII 10)
\t matches a tab character (ASCII 9)
Named Capture Group host_ip
(?P<host_ip>[^\t]+)
Match a single character not present in the list below
[^\t]
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
\t matches a tab character (ASCII 9)
Match a single character not present in the list below
[^\t\n]
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
\t matches a tab character (ASCII 9)
\n matches a line-feed (newline) character (ASCII 10)
\t matches a tab character (ASCII 9)
Named Capture Group username
(?P<username>[a-z]+_[a-z]+)
Match a single character present in the list below
[a-z]
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
a-z matches a single character in the range between a (index 97) and z (index 122) (case sensitive)
_ matches the character _ with index 9510 (5F16 or 1378) literally (case sensitive)
Match a single character present in the list below
[a-z]
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
a-z matches a single character in the range between a (index 97) and z (index 122) (case sensitive)
Your regular expression does not match the subject string.Try launching the debugger to find out why.

Regular Expression
No Match

/
/

Test String