Regular Expressions 101

Save & Share

  • Save Regex
    ctrl+s
  • Update Regex
    ctrl+⇧+s

Flavor

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

Function

  • Match
  • Substitution
  • List
  • Unit Tests
"
^ School\s*=\s*(?P<school_name>.+) (?P<school_content>[\s\S]+?) (?=^School|\Z)
"
gmx
^ asserts position at start of a line
School
matches the characters School literally (case sensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v  ])
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
= matches the character = with index 6110 (3D16 or 758) literally (case sensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v  ])
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
Named Capture Group school_name
(?P<school_name>.+)
.
matches any character (except for line terminators)
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
Named Capture Group school_content
(?P<school_content>[\s\S]+?)
Match a single character present in the list below
[\s\S]
+? matches the previous token between one and unlimited times, as few times as possible, expanding as needed (lazy)
\s matches any whitespace character (equivalent to [\r\n\t\f\v  ])
\S matches any non-whitespace character (equivalent to [^\r\n\t\f\v ])
Positive Lookahead
(?=^School|\Z)
Assert that the Regex below matches
1st Alternative
^School
^ asserts position at start of a line
School
matches the characters School literally (case sensitive)
2nd Alternative
\Z
\Z asserts position at the end of the string, or before the line terminator right at the end of the string (if any)
Global pattern flags
g modifier: global. All matches (don't return after first match)
m modifier: multi line. Causes ^ and $ to match the begin/end of each line (not only begin/end of string)
x modifier: extended. Spaces and text after a # in the pattern are ignored
Your regular expression does not match the subject string.

Regular Expression
No Match

r"
"
gmx

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 Ruby, please visit: http://ruby-doc.org/core-2.2.0/Regexp.html