Regular Expressions 101

Save & Share

  • Save Regex
    ctrl+s
  • Update Regex
    ctrl+⇧+s

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])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-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])+)\])
/
gm
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 6110 (3D16 or 758) literally (case sensitive)
?^_`{|}~-
matches a single character in the list ?^_`{|}~- (case sensitive)
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 6110 (3D16 or 758) literally (case sensitive)
?^_`{|}~-
matches a single character in the list ?^_`{|}~- (case sensitive)
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])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-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)
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)
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
\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-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
(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}
{3} matches the previous token exactly 3 times
Non-capturing group
(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))
1st Capturing Group
(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])
1st Alternative
2(5[0-5]|[0-4][0-9])
2 matches the character 2 with index 5010 (3216 or 628) literally (case sensitive)
2nd Capturing Group
(5[0-5]|[0-4][0-9])
1st Alternative
5[0-5]
5 matches the character 5 with index 5310 (3516 or 658) 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
[0-4][0-9]
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)
2nd Alternative
1[0-9][0-9]
1 matches the character 1 with index 4910 (3116 or 618) literally (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]
0-9 matches a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)
3rd Alternative
[1-9]?[0-9]
Match a single character present in the list below
[1-9]
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
1-9 matches a single character in the range between 1 (index 49) and 9 (index 57) (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)
\. matches the character . with index 4610 (2E16 or 568) literally (case sensitive)
Non-capturing group
(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-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
(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])
3rd Capturing Group
(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])
1st Alternative
2(5[0-5]|[0-4][0-9])
2 matches the character 2 with index 5010 (3216 or 628) literally (case sensitive)
4th Capturing Group
(5[0-5]|[0-4][0-9])
1st Alternative
5[0-5]
5 matches the character 5 with index 5310 (3516 or 658) 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
[0-4][0-9]
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)
2nd Alternative
1[0-9][0-9]
1 matches the character 1 with index 4910 (3116 or 618) literally (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]
0-9 matches a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)
3rd Alternative
[1-9]?[0-9]
Match a single character present in the list below
[1-9]
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
1-9 matches a single character in the range between 1 (index 49) and 9 (index 57) (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)
2nd 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)
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
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

Code Generator

Generated Code

Loading code sample...
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report.
For a full regex reference for JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions