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
"
^(Pag. del \d{2}\/\d{2}\/\d{2} ora \d{2}:\d{2} presso: |)(.*?) (IT\*.*)?(FR|LU|IT|ITA) Carta.*$
"
gm
^ asserts position at start of a line
1st Capturing Group
(Pag. del \d{2}\/\d{2}\/\d{2} ora \d{2}:\d{2} presso: |)
1st Alternative
Pag. del \d{2}\/\d{2}\/\d{2} ora \d{2}:\d{2} presso:
Pag
matches the characters Pag literally (case sensitive)
. matches any character (except for line terminators)
del
matches the characters del literally (case sensitive)
\d
matches a digit (equivalent to [0-9])
{2} matches the previous token exactly 2 times
\/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
\d
matches a digit (equivalent to [0-9])
{2} matches the previous token exactly 2 times
\/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
\d
matches a digit (equivalent to [0-9])
{2} matches the previous token exactly 2 times
ora
matches the characters ora literally (case sensitive)
\d
matches a digit (equivalent to [0-9])
{2} matches the previous token exactly 2 times
: matches the character : with index 5810 (3A16 or 728) literally (case sensitive)
\d
matches a digit (equivalent to [0-9])
{2} matches the previous token exactly 2 times
presso:
matches the characters presso: literally (case sensitive)
2nd Alternative null, matches any position
2nd Capturing Group
(.*?)
.
matches any character (except for line terminators)
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
matches the character with index 3210 (2016 or 408) literally (case sensitive)
3rd Capturing Group
(IT\*.*)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
IT
matches the characters IT literally (case sensitive)
\* matches the character * with index 4210 (2A16 or 528) 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)
4th Capturing Group
(FR|LU|IT|ITA)
1st Alternative
FR
FR
matches the characters FR literally (case sensitive)
2nd Alternative
LU
LU
matches the characters LU literally (case sensitive)
3rd Alternative
IT
IT
matches the characters IT literally (case sensitive)
4th Alternative
ITA
ITA
matches the characters ITA literally (case sensitive)
Carta
matches the characters Carta 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
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)
Your regular expression does not match the subject string.

Regular Expression
No Match

r"
"
gm

Test String

Substitution

Processing...