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-Za-z0-9!#$%&'*+/=?.^_`{|}~-]+(?:.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[x01-x08x0bx0cx0e-x1fx21x23-x5bx5d-x7f]|[x01-x09x0bx0cx0e-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-x08x0bx0cx0e-x1fx21-x5ax53-x7f]|[x01-x09x0bx0cx0e-x7f])+)])
"
gm
Non-capturing group
(?:[A-Za-z0-9!#$%&'*+/=?.^_`{|}~-]+(?:.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[x01-x08x0bx0cx0e-x1fx21x23-x5bx5d-x7f]|[x01-x09x0bx0cx0e-x7f])*\")
1st Alternative
[A-Za-z0-9!#$%&'*+/=?.^_`{|}~-]+(?:.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*
Match a single character present in the list below
[A-Za-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 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)
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)
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 any character (except for line terminators)
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)
2nd Alternative
\"(?:[x01-x08x0bx0cx0e-x1fx21x23-x5bx5d-x7f]|[x01-x09x0bx0cx0e-x7f])*\"
\" matches the character " with index 3410 (2216 or 428) literally (case sensitive)
Non-capturing group
(?:[x01-x08x0bx0cx0e-x1fx21x23-x5bx5d-x7f]|[x01-x09x0bx0cx0e-x7f])*
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
1st Alternative
[x01-x08x0bx0cx0e-x1fx21x23-x5bx5d-x7f]
Match a single character present in the list below
[x01-x08x0bx0cx0e-x1fx21x23-x5bx5d-x7f]
x0
matches a single character in the list x0 (case sensitive)
1-x matches a single character in the range between 1 (index 49) and x (index 120) (case sensitive)
08x0bx0cx0
matches a single character in the list 08xbc (case sensitive)
e-x matches a single character in the range between e (index 101) and x (index 120) (case sensitive)
1fx21x2
matches a single character in the list 1fx2 (case sensitive)
3-x matches a single character in the range between 3 (index 51) and x (index 120) (case sensitive)
5bx5
matches a single character in the list 5bx (case sensitive)
d-x matches a single character in the range between d (index 100) and x (index 120) (case sensitive)
7f
matches a single character in the list 7f (case sensitive)
2nd Alternative
[x01-x09x0bx0cx0e-x7f]
Match a single character present in the list below
[x01-x09x0bx0cx0e-x7f]
x0
matches a single character in the list x0 (case sensitive)
1-x matches a single character in the range between 1 (index 49) and x (index 120) (case sensitive)
09x0bx0cx0
matches a single character in the list 09xbc (case sensitive)
e-x matches a single character in the range between e (index 101) and x (index 120) (case sensitive)
7f
matches a single character in the list 7f (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-x08x0bx0cx0e-x1fx21-x5ax53-x7f]|[x01-x09x0bx0cx0e-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 any character (except for line terminators)
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-x08x0bx0cx0e-x1fx21-x5ax53-x7f]|[x01-x09x0bx0cx0e-x7f])+)]
Match a single character present in the list below
[(?:(?:(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-x08x0bx0cx0e-x1fx21-x5ax53-x7f]|[x01-x09x0bx0cx0e-x7f])+)]
(?:(?:(2(5
matches a single character in the list (?:25 (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)
| matches the character | with index 12410 (7C16 or 1748) 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)
)|1
matches a single character in the list )|1 (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)
| matches the character | with index 12410 (7C16 or 1748) literally (case sensitive)
Match a single character present in the list below
[1-9]
1-9 matches a single character in the range between 1 (index 49) and 9 (index 57) (case sensitive)
? matches the character ? with index 6310 (3F16 or 778) 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)
)).){3}(?:(2(5
matches a single character in the list ).{3}(?:25 (case sensitive)
Match a single character present in the list below
[0-5]
| matches the character | with index 12410 (7C16 or 1748) literally (case sensitive)
Match a single character present in the list below
[0-4]
Match a single character present in the list below
[0-9]
)|1
matches a single character in the list )|1 (case sensitive)
Match a single character present in the list below
[0-9]
Match a single character present in the list below
[0-9]
| matches the character | with index 12410 (7C16 or 1748) literally (case sensitive)
Match a single character present in the list below
[1-9]
? matches the character ? with index 6310 (3F16 or 778) literally (case sensitive)
Match a single character present in the list below
[0-9]
)|
matches a single character in the list )| (case sensitive)
Match a single character present in the list below
[a-z0-9-]
* matches the character * with index 4210 (2A16 or 528) literally (case sensitive)
Match a single character present in the list below
[a-z0-9]
:(?:
matches a single character in the list :(? (case sensitive)
Match a single character present in the list below
[x01-x08x0bx0cx0e-x1fx21-x5ax53-x7f]
| matches the character | with index 12410 (7C16 or 1748) literally (case sensitive)
Match a single character present in the list below
[x01-x09x0bx0cx0e-x7f]
)+)
matches a single character in the list )+ (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

"
"
gm

Test String