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
"
^(.*\[(error|warning|notice|info|debug)\].*)$
"
mg
^ asserts position at start of a line
1st Capturing Group
(.*\[(error|warning|notice|info|debug)\].*)
.
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)
\[ matches the character [ with index 9110 (5B16 or 1338) literally (case sensitive)
2nd Capturing Group
(error|warning|notice|info|debug)
1st Alternative
error
error
matches the characters error literally (case sensitive)
2nd Alternative
warning
warning
matches the characters warning literally (case sensitive)
3rd Alternative
notice
notice
matches the characters notice literally (case sensitive)
4th Alternative
info
info
matches the characters info literally (case sensitive)
5th Alternative
debug
debug
matches the characters debug literally (case sensitive)
\] matches the character ] with index 9310 (5D16 or 1358) literally (case sensitive)
.
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)
$ asserts position at the end of a line
Global pattern flags
m modifier: multi line. Causes ^ and $ to match the begin/end of each line (not only begin/end of string)
g modifier: global. All matches (don't return after first match)
Your regular expression does not match the subject string.

Regular Expression
No Match

r"
"
mg

Test String

Code Generator

Generated Code

Loading code sample...
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report.
For a full regex reference for Golang, please visit: https://golang.org/pkg/regexp/