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
"
(above|below|title|data[0-9]*|header[0-9]*|caption|above|label[0-9]*) *= +([^{}|\n]+)[^| \n]
"
g
1st Capturing Group
(above|below|title|data[0-9]*|header[0-9]*|caption|above|label[0-9]*)
1st Alternative
above
above
matches the characters above literally (case sensitive)
2nd Alternative
below
below
matches the characters below literally (case sensitive)
3rd Alternative
title
title
matches the characters title literally (case sensitive)
4th Alternative
data[0-9]*
data
matches the characters data literally (case sensitive)
Match a single character present in the list below
[0-9]
* matches the previous token between zero and unlimited 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)
5th Alternative
header[0-9]*
header
matches the characters header literally (case sensitive)
Match a single character present in the list below
[0-9]
* matches the previous token between zero and unlimited 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)
6th Alternative
caption
caption
matches the characters caption literally (case sensitive)
7th Alternative
above
above
matches the characters above literally (case sensitive)
8th Alternative
label[0-9]*
label
matches the characters label literally (case sensitive)
Match a single character present in the list below
[0-9]
* matches the previous token between zero and unlimited 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 3210 (2016 or 408) literally (case sensitive)
= matches the character = with index 6110 (3D16 or 758) literally (case sensitive)
matches the character with index 3210 (2016 or 408) literally (case sensitive)
2nd Capturing Group
([^{}|\n]+)
Match a single character not present in the list below
[^{}|\n]
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
{}|
matches a single character in the list {}| (case sensitive)
\n matches a line-feed (newline) character (ASCII 10)
Match a single character not present in the list below
[^| \n]
|
matches a single character in the list | (case sensitive)
\n matches a line-feed (newline) character (ASCII 10)
Global pattern flags
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"
"
g

Test String