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
/
(?:[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])
/
mg
Non-capturing group
(?:[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")
1st Alternative
[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*
Match a single character present in the list below
[a-z0-9!#$%&'*+\/=?^_`{|}~-]
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
a-z matches a single character in the range between a (index 97) and z (index 122) (case sensitive)
0-9 matches a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)
!#$%&'*+
matches a single character in the list !#$%&'*+ (case sensitive)
\/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
=?^_`{|}~
matches a single character in the list =?^_`{|}~ (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!
Non-capturing group
(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
\. matches the character . with index 4610 (2E16 or 568) literally (case sensitive)
Match a single character present in the list below
[a-z0-9!#$%&'*+\/=?^_`{|}~-]
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
a-z matches a single character in the range between a (index 97) and z (index 122) (case sensitive)
0-9 matches a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)
!#$%&'*+
matches a single character in the list !#$%&'*+ (case sensitive)
\/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
=?^_`{|}~
matches a single character in the list =?^_`{|}~ (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!
2nd Alternative
"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*"
" matches the character " with index 3410 (2216 or 428) literally (case sensitive)
Non-capturing group
(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
1st Alternative
[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]
Match a single character present in the list below
[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]
\x01-\x08 matches a single character in the range between  (index 1) and  (index 8) (case sensitive)
\x0b matches the character with index B16 (1110 or 138) literally (case sensitive)
\x0c matches the character with index C16 (1210 or 148) literally (case sensitive)
\x0e-\x1f matches a single character in the range between  (index 14) and  (index 31) (case sensitive)
\x21 matches the character ! with index 2116 (3310 or 418) literally (case sensitive)
\x23-\x5b matches a single character in the range between # (index 35) and [ (index 91) (case sensitive)
\x5d-\x7f matches a single character in the range between ] (index 93) and  (index 127) (case sensitive)
2nd Alternative
\\[\x01-\x09\x0b\x0c\x0e-\x7f]
\\ matches the character \ with index 9210 (5C16 or 1348) literally (case sensitive)
Match a single character present in the list below
[\x01-\x09\x0b\x0c\x0e-\x7f]
\x01-\x09 matches a single character in the range between  (index 1) and (index 9) (case sensitive)
\x0b matches the character with index B16 (1110 or 138) literally (case sensitive)
\x0c matches the character with index C16 (1210 or 148) literally (case sensitive)
\x0e-\x7f matches a single character in the range between  (index 14) and  (index 127) (case sensitive)
" matches the character " with index 3410 (2216 or 428) literally (case sensitive)
@ matches the character @ with index 6410 (4016 or 1008) literally (case sensitive)
Non-capturing group
(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])
1st Alternative
(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?
Non-capturing group
(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
Match a single character present in the list below
[a-z0-9]
a-z matches a single character in the range between a (index 97) and z (index 122) (case sensitive)
0-9 matches a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)
Non-capturing group
(?:[a-z0-9-]*[a-z0-9])?
? 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
[a-z0-9-]
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
a-z matches a single character in the range between a (index 97) and z (index 122) (case sensitive)
0-9 matches a single character in the range between 0 (index 48) and 9 (index 57) (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!
Match a single character present in the list below
[a-z0-9]
a-z matches a single character in the range between a (index 97) and z (index 122) (case sensitive)
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
[a-z0-9]
a-z matches a single character in the range between a (index 97) and z (index 122) (case sensitive)
0-9 matches a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)
Non-capturing group
(?:[a-z0-9-]*[a-z0-9])?
? 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
[a-z0-9-]
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
a-z matches a single character in the range between a (index 97) and z (index 122) (case sensitive)
0-9 matches a single character in the range between 0 (index 48) and 9 (index 57) (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!
Match a single character present in the list below
[a-z0-9]
a-z matches a single character in the range between a (index 97) and z (index 122) (case sensitive)
0-9 matches a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)
2nd Alternative
\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\]
\[ matches the character [ with index 9110 (5B16 or 1338) literally (case sensitive)
Non-capturing group
(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}
{3} matches the previous token exactly 3 times
Non-capturing group
(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)
1st Alternative
25[0-5]
25
matches the characters 25 literally (case sensitive)
Match a single character present in the list below
[0-5]
0-5 matches a single character in the range between 0 (index 48) and 5 (index 53) (case sensitive)
2nd Alternative
2[0-4][0-9]
2 matches the character 2 with index 5010 (3216 or 628) literally (case sensitive)
Match a single character present in the list below
[0-4]
0-4 matches a single character in the range between 0 (index 48) and 4 (index 52) (case sensitive)
Match a single character present in the list below
[0-9]
0-9 matches a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)
3rd Alternative
[01]?[0-9][0-9]?
Match a single character present in the list below
[01]
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
01
matches a single character in the list 01 (case sensitive)
Match a single character present in the list below
[0-9]
0-9 matches a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)
Match a single character present in the list below
[0-9]
? matches the previous token between zero and one 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)
Non-capturing group
(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)
1st Alternative
25[0-5]
25
matches the characters 25 literally (case sensitive)
Match a single character present in the list below
[0-5]
0-5 matches a single character in the range between 0 (index 48) and 5 (index 53) (case sensitive)
2nd Alternative
2[0-4][0-9]
2 matches the character 2 with index 5010 (3216 or 628) literally (case sensitive)
Match a single character present in the list below
[0-4]
0-4 matches a single character in the range between 0 (index 48) and 4 (index 52) (case sensitive)
Match a single character present in the list below
[0-9]
0-9 matches a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)
3rd Alternative
[01]?[0-9][0-9]?
Match a single character present in the list below
[01]
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
01
matches a single character in the list 01 (case sensitive)
Match a single character present in the list below
[0-9]
0-9 matches a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)
Match a single character present in the list below
[0-9]
? matches the previous token between zero and one 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)
4th Alternative
[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+
Match a single character present in the list below
[a-z0-9-]
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
a-z matches a single character in the range between a (index 97) and z (index 122) (case sensitive)
0-9 matches a single character in the range between 0 (index 48) and 9 (index 57) (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!
Match a single character present in the list below
[a-z0-9]
a-z matches a single character in the range between a (index 97) and z (index 122) (case sensitive)
0-9 matches a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)
: matches the character : with index 5810 (3A16 or 728) literally (case sensitive)
Non-capturing group
(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
1st Alternative
[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]
Match a single character present in the list below
[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]
\x01-\x08 matches a single character in the range between  (index 1) and  (index 8) (case sensitive)
\x0b matches the character with index B16 (1110 or 138) literally (case sensitive)
\x0c matches the character with index C16 (1210 or 148) literally (case sensitive)
\x0e-\x1f matches a single character in the range between  (index 14) and  (index 31) (case sensitive)
\x21-\x5a matches a single character in the range between ! (index 33) and Z (index 90) (case sensitive)
\x53-\x7f matches a single character in the range between S (index 83) and  (index 127) (case sensitive)
2nd Alternative
\\[\x01-\x09\x0b\x0c\x0e-\x7f]
\\ matches the character \ with index 9210 (5C16 or 1348) literally (case sensitive)
Match a single character present in the list below
[\x01-\x09\x0b\x0c\x0e-\x7f]
\x01-\x09 matches a single character in the range between  (index 1) and (index 9) (case sensitive)
\x0b matches the character with index B16 (1110 or 138) literally (case sensitive)
\x0c matches the character with index C16 (1210 or 148) literally (case sensitive)
\x0e-\x7f matches a single character in the range between  (index 14) and  (index 127) (case sensitive)
\] matches the character ] with index 9310 (5D16 or 1358) literally (case sensitive)
Global pattern flags
m modifier: multi line. Causes ^ and $ to match the begin/end of each line (not only begin/end of string)
g modifier: global. All matches (don't return after first match)
Your regular expression does not match the subject string.

Regular Expression
No Match

/
/
mg

Test String