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
/
(?(DEFINE) # start DEFINE block # pre-define quant subroutine (?<quant>many|some|five) # pre-define adj subroutine (?<adj>blue|large|interesting) # pre-define object subroutine (?<object>cars|elephants|problems) # pre-define noun_phrase subroutine (?<noun_phrase>(?&quant)\ (?&adj)\ (?&object)) # pre-define verb subroutine (?<verb>borrow|solve|ressemble) ) # end DEFINE block ##### The regex matching starts here ##### (?&noun_phrase)\ (?&verb)\ (?&noun_phrase)
/
xg
Subpattern definition construct
(?(DEFINE) # start DEFINE block # pre-define quant subroutine (?<quant>many|some|five) # pre-define adj subroutine (?<adj>blue|large|interesting) # pre-define object subroutine (?<object>cars|elephants|problems) # pre-define noun_phrase subroutine (?<noun_phrase>(?&quant)\ (?&adj)\ (?&object)) # pre-define verb subroutine (?<verb>borrow|solve|ressemble) )
May only be used to define functions. No matching is done in this group.
# start DEFINE block
start DEFINE block
Comment: start DEFINE block
# pre-define quant subroutine
pre-define quant subroutine
Comment: pre-define quant subroutine
Named Capture Group quant
(?<quant>many|some|five)
1st Alternative
many
many
matches the characters many literally (case sensitive)
2nd Alternative
some
some
matches the characters some literally (case sensitive)
3rd Alternative
five
five
matches the characters five literally (case sensitive)
# pre-define adj subroutine
pre-define adj subroutine
Comment: pre-define adj subroutine
Named Capture Group adj
(?<adj>blue|large|interesting)
1st Alternative
blue
blue
matches the characters blue literally (case sensitive)
2nd Alternative
large
large
matches the characters large literally (case sensitive)
3rd Alternative
interesting
interesting
matches the characters interesting literally (case sensitive)
# pre-define object subroutine
pre-define object subroutine
Comment: pre-define object subroutine
Named Capture Group object
(?<object>cars|elephants|problems)
1st Alternative
cars
cars
matches the characters cars literally (case sensitive)
2nd Alternative
elephants
elephants
matches the characters elephants literally (case sensitive)
3rd Alternative
problems
problems
matches the characters problems literally (case sensitive)
# pre-define noun_phrase subroutine
pre-define noun_phrase subroutine
Comment: pre-define noun_phrase subroutine
Named Capture Group noun_phrase
(?<noun_phrase>(?&quant)\ (?&adj)\ (?&object))
(?&quant) recurses the subpattern named quant
\ matches the character with index 3210 (2016 or 408) literally (case sensitive)
(?&adj) recurses the subpattern named adj
\ matches the character with index 3210 (2016 or 408) literally (case sensitive)
(?&object) recurses the subpattern named object
# pre-define verb subroutine
pre-define verb subroutine
Comment: pre-define verb subroutine
Named Capture Group verb
(?<verb>borrow|solve|ressemble)
1st Alternative
borrow
borrow
matches the characters borrow literally (case sensitive)
2nd Alternative
solve
3rd Alternative
ressemble
# end DEFINE block
end DEFINE block
Comment: end DEFINE block
##### The regex matching starts here #####
#### The regex matching starts here #####
Comment: #### The regex matching starts here #####
(?&noun_phrase) recurses the subpattern named noun_phrase
\ matches the character with index 3210 (2016 or 408) literally (case sensitive)
(?&verb) recurses the subpattern named verb
\ matches the character with index 3210 (2016 or 408) literally (case sensitive)
(?&noun_phrase) recurses the subpattern named noun_phrase
Global pattern flags
x modifier: extended. Spaces and text after a # in the pattern are ignored
g modifier: global. All matches (don't return after first match)
Your regular expression does not match the subject string.Try launching the debugger to find out why.

Regular Expression
No Match

/
/
xg

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 Python, please visit: https://docs.python.org/3/library/re.html