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 (9)
/
^P((\d+([,\.]\d+)?Y)?(\d+([,\.]\d+)?M)?(\d+([,\.]\d+)?D)?(T(\d+([,\.]\d+)?H)?(\d+([,\.]\d+)?M)?(\d+([,\.]\d+)?S)?)?$)|(\d+([,\.]\d+)?W$)
/
gm
1st Alternative
^P((\d+([,\.]\d+)?Y)?(\d+([,\.]\d+)?M)?(\d+([,\.]\d+)?D)?(T(\d+([,\.]\d+)?H)?(\d+([,\.]\d+)?M)?(\d+([,\.]\d+)?S)?)?$)
^ asserts position at start of a line
P matches the character P with index 8010 (5016 or 1208) literally (case sensitive)
1st Capturing Group
((\d+([,\.]\d+)?Y)?(\d+([,\.]\d+)?M)?(\d+([,\.]\d+)?D)?(T(\d+([,\.]\d+)?H)?(\d+([,\.]\d+)?M)?(\d+([,\.]\d+)?S)?)?$)
2nd Capturing Group
(\d+([,\.]\d+)?Y)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
\d
matches a digit (equivalent to [0-9])
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
3rd Capturing Group
([,\.]\d+)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
Match a single character present in the list below
[,\.]
, matches the character , with index 4410 (2C16 or 548) literally (case sensitive)
\. matches the character . with index 4610 (2E16 or 568) literally (case sensitive)
\d
matches a digit (equivalent to [0-9])
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
Y matches the character Y with index 8910 (5916 or 1318) literally (case sensitive)
4th Capturing Group
(\d+([,\.]\d+)?M)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
\d
matches a digit (equivalent to [0-9])
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
5th Capturing Group
([,\.]\d+)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
Match a single character present in the list below
[,\.]
, matches the character , with index 4410 (2C16 or 548) literally (case sensitive)
\. matches the character . with index 4610 (2E16 or 568) literally (case sensitive)
\d
matches a digit (equivalent to [0-9])
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
M matches the character M with index 7710 (4D16 or 1158) literally (case sensitive)
6th Capturing Group
(\d+([,\.]\d+)?D)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
\d
matches a digit (equivalent to [0-9])
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
7th Capturing Group
([,\.]\d+)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
Match a single character present in the list below
[,\.]
, matches the character , with index 4410 (2C16 or 548) literally (case sensitive)
\. matches the character . with index 4610 (2E16 or 568) literally (case sensitive)
\d
matches a digit (equivalent to [0-9])
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
D matches the character D with index 6810 (4416 or 1048) literally (case sensitive)
8th Capturing Group
(T(\d+([,\.]\d+)?H)?(\d+([,\.]\d+)?M)?(\d+([,\.]\d+)?S)?)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
T matches the character T with index 8410 (5416 or 1248) literally (case sensitive)
9th Capturing Group
(\d+([,\.]\d+)?H)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
\d
matches a digit (equivalent to [0-9])
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
10th Capturing Group
([,\.]\d+)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
Match a single character present in the list below
[,\.]
, matches the character , with index 4410 (2C16 or 548) literally (case sensitive)
\. matches the character . with index 4610 (2E16 or 568) literally (case sensitive)
\d
matches a digit (equivalent to [0-9])
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
H matches the character H with index 7210 (4816 or 1108) literally (case sensitive)
11th Capturing Group
(\d+([,\.]\d+)?M)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
\d
matches a digit (equivalent to [0-9])
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
12th Capturing Group
([,\.]\d+)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
Match a single character present in the list below
[,\.]
, matches the character , with index 4410 (2C16 or 548) literally (case sensitive)
\. matches the character . with index 4610 (2E16 or 568) literally (case sensitive)
\d
matches a digit (equivalent to [0-9])
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
M matches the character M with index 7710 (4D16 or 1158) literally (case sensitive)
13th Capturing Group
(\d+([,\.]\d+)?S)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
\d
matches a digit (equivalent to [0-9])
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
14th Capturing Group
([,\.]\d+)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
Match a single character present in the list below
[,\.]
, matches the character , with index 4410 (2C16 or 548) literally (case sensitive)
\. matches the character . with index 4610 (2E16 or 568) literally (case sensitive)
\d
matches a digit (equivalent to [0-9])
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
S matches the character S with index 8310 (5316 or 1238) literally (case sensitive)
$ asserts position at the end of a line
2nd Alternative
(\d+([,\.]\d+)?W$)
15th Capturing Group
(\d+([,\.]\d+)?W$)
\d
matches a digit (equivalent to [0-9])
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
16th Capturing Group
([,\.]\d+)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
Match a single character present in the list below
[,\.]
, matches the character , with index 4410 (2C16 or 548) literally (case sensitive)
\. matches the character . with index 4610 (2E16 or 568) literally (case sensitive)
\d
matches a digit (equivalent to [0-9])
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
W matches the character W with index 8710 (5716 or 1278) literally (case sensitive)
$ 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

/
/
gm

Test String