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
/
(\d{4}\/\d{2}\/\d{2} \d{2}:\d{2}:\d{2})([\s\S])( Crafting plot )([0-9]{1,})( out of)|(Total plot creation time was )([0-9]{1,}\.[0-9]{1,})( sec)+
/
gm
1st Alternative
(\d{4}\/\d{2}\/\d{2} \d{2}:\d{2}:\d{2})([\s\S])( Crafting plot )([0-9]{1,})( out of)
1st Capturing Group
(\d{4}\/\d{2}\/\d{2} \d{2}:\d{2}:\d{2})
\d
matches a digit (equivalent to [0-9])
{4} matches the previous token exactly 4 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
matches the character with index 3210 (2016 or 408) 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
: 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
2nd Capturing Group
([\s\S])
Match a single character present in the list below
[\s\S]
\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 ])
3rd Capturing Group
( Crafting plot )
Crafting plot
matches the characters Crafting plot literally (case sensitive)
4th Capturing Group
([0-9]{1,})
Match a single character present in the list below
[0-9]
{1,} matches the previous token between one 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 Capturing Group
( out of)
out of
matches the characters out of literally (case sensitive)
2nd Alternative
(Total plot creation time was )([0-9]{1,}\.[0-9]{1,})( sec)+
6th Capturing Group
(Total plot creation time was )
Total plot creation time was
matches the characters Total plot creation time was literally (case sensitive)
7th Capturing Group
([0-9]{1,}\.[0-9]{1,})
Match a single character present in the list below
[0-9]
{1,} matches the previous token between one 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 4610 (2E16 or 568) literally (case sensitive)
Match a single character present in the list below
[0-9]
{1,} matches the previous token between one 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)
8th Capturing Group
( sec)+
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
A repeated capturing group will only capture the last iteration. Put a capturing group around the repeated group to capture all iterations or use a non-capturing group instead if you're not interested in the data
sec
matches the characters sec literally (case sensitive)
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.Try launching the debugger to find out why.

Regular Expression
No Match

/
/
gm

Test String