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
"
(?:\s*?NAME\s*?:\s*?\"?)([0-9A-Za-z- ,]+)(?:\"?\s*?,\s*?)(?:DESCR\s*?:\s*\"?)([0-9A-Za-z- ,/+:]+)(?:\"?\s*?PID\s*?:\s*?)([0-9A-Z-]+)(?:\s*?,\s*?VID\s*?:\s*?)([0-9A-Z/]+)(?:\s*?,\s*?SN\s*?:\s*?)([0-9A-Z/]+)
"
gm
Non-capturing group
(?:\s*?NAME\s*?:\s*?\"?)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v  ])
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
NAME
matches the characters NAME literally (case sensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v  ])
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
: matches the character : with index 5810 (3A16 or 728) literally (case sensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v  ])
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
\"
matches the character " with index 3410 (2216 or 428) literally (case sensitive)
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
1st Capturing Group
([0-9A-Za-z- ,]+)
Match a single character present in the list below
[0-9A-Za-z- ,]
+ 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)
A-Z matches a single character in the range between A (index 65) and Z (index 90) (case sensitive)
a-z matches a single character in the range between a (index 97) and z (index 122) (case sensitive)
- matches the character - with index 4510 (2D16 or 558) literally (case sensitive)
This hyphen is treated literally, which might be confusing for others. Consider escaping it or placing at the start or end of the class!
,
matches a single character in the list , (case sensitive)
Non-capturing group
(?:\"?\s*?,\s*?)
\"
matches the character " with index 3410 (2216 or 428) literally (case sensitive)
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v  ])
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
, matches the character , with index 4410 (2C16 or 548) literally (case sensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v  ])
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
Non-capturing group
(?:DESCR\s*?:\s*\"?)
DESCR
matches the characters DESCR literally (case sensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v  ])
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
: matches the character : with index 5810 (3A16 or 728) literally (case sensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v  ])
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
\"
matches the character " with index 3410 (2216 or 428) literally (case sensitive)
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
2nd Capturing Group
([0-9A-Za-z- ,/+:]+)
Match a single character present in the list below
[0-9A-Za-z- ,/+:]
+ 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)
A-Z matches a single character in the range between A (index 65) and Z (index 90) (case sensitive)
a-z matches a single character in the range between a (index 97) and z (index 122) (case sensitive)
- matches the character - with index 4510 (2D16 or 558) literally (case sensitive)
This hyphen is treated literally, which might be confusing for others. Consider escaping it or placing at the start or end of the class!
,/+:
matches a single character in the list ,/+: (case sensitive)
Non-capturing group
(?:\"?\s*?PID\s*?:\s*?)
\"
matches the character " with index 3410 (2216 or 428) literally (case sensitive)
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v  ])
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
PID
matches the characters PID literally (case sensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v  ])
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
: matches the character : with index 5810 (3A16 or 728) literally (case sensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v  ])
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
3rd Capturing Group
([0-9A-Z-]+)
Match a single character present in the list below
[0-9A-Z-]
+ 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)
A-Z matches a single character in the range between A (index 65) and Z (index 90) (case sensitive)
- matches the character - with index 4510 (2D16 or 558) literally (case sensitive)
Non-capturing group
(?:\s*?,\s*?VID\s*?:\s*?)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v  ])
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
, matches the character , with index 4410 (2C16 or 548) literally (case sensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v  ])
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
VID
matches the characters VID literally (case sensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v  ])
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
: matches the character : with index 5810 (3A16 or 728) literally (case sensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v  ])
4th Capturing Group
([0-9A-Z/]+)
Match a single character present in the list below
[0-9A-Z/]
+ 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)
A-Z matches a single character in the range between A (index 65) and Z (index 90) (case sensitive)
/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
Non-capturing group
(?:\s*?,\s*?SN\s*?:\s*?)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v  ])
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
, matches the character , with index 4410 (2C16 or 548) literally (case sensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v  ])
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
SN
matches the characters SN literally (case sensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v  ])
: matches the character : with index 5810 (3A16 or 728) literally (case sensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v  ])
5th Capturing Group
([0-9A-Z/]+)
Match a single character present in the list below
[0-9A-Z/]
+ 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)
A-Z matches a single character in the range between A (index 65) and Z (index 90) (case sensitive)
/ matches the character / with index 4710 (2F16 or 578) 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.

Regular Expression
No Match

r"
"
gm

Test String

Substitution

Processing...