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
/
\b(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\x{00a1}-\x{ffff}0-9]+-?)*[a-z\x{00a1}-\x{ffff}0-9]+)(?:\.(?:[a-z\x{00a1}-\x{ffff}0-9]+-?)*[a-z\x{00a1}-\x{ffff}0-9]+)*(?:\.(?:[a-z\x{00a1}-\x{ffff}]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?\b
/
gi
\b assert position at a word boundary: (^\w|\w$|\W\w|\w\W)
Non-capturing group
(?:(?:https?|ftp):\/\/)
Non-capturing group
(?:https?|ftp)
1st Alternative
https?
http
matches the characters http literally (case insensitive)
s
matches the character s with index 11510 (7316 or 1638) literally (case insensitive)
2nd Alternative
ftp
ftp
matches the characters ftp literally (case insensitive)
: matches the character : with index 5810 (3A16 or 728) literally (case insensitive)
\/ matches the character / with index 4710 (2F16 or 578) literally (case insensitive)
\/ matches the character / with index 4710 (2F16 or 578) literally (case insensitive)
Non-capturing group
(?:\S+(?::\S*)?@)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
\S
matches any non-whitespace character (equivalent to [^\r\n\t\f\v ])
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
Non-capturing group
(?::\S*)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
: matches the character : with index 5810 (3A16 or 728) literally (case insensitive)
\S
matches any non-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 6410 (4016 or 1008) literally (case insensitive)
Non-capturing group
(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\x{00a1}-\x{ffff}0-9]+-?)*[a-z\x{00a1}-\x{ffff}0-9]+)(?:\.(?:[a-z\x{00a1}-\x{ffff}0-9]+-?)*[a-z\x{00a1}-\x{ffff}0-9]+)*(?:\.(?:[a-z\x{00a1}-\x{ffff}]{2,})))
1st Alternative
(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))
Negative Lookahead
(?!10(?:\.\d{1,3}){3})
Assert that the Regex below does not match
10
matches the characters 10 literally (case insensitive)
Non-capturing group
(?:\.\d{1,3}){3}
{3} matches the previous token exactly 3 times
\. matches the character . with index 4610 (2E16 or 568) literally (case insensitive)
\d
matches a digit (equivalent to [0-9])
{1,3} matches the previous token between 1 and 3 times, as many times as possible, giving back as needed (greedy)
Negative Lookahead
(?!127(?:\.\d{1,3}){3})
Assert that the Regex below does not match
127
matches the characters 127 literally (case insensitive)
Non-capturing group
(?:\.\d{1,3}){3}
{3} matches the previous token exactly 3 times
\. matches the character . with index 4610 (2E16 or 568) literally (case insensitive)
\d
matches a digit (equivalent to [0-9])
{1,3} matches the previous token between 1 and 3 times, as many times as possible, giving back as needed (greedy)
Negative Lookahead
(?!169\.254(?:\.\d{1,3}){2})
Assert that the Regex below does not match
169
matches the characters 169 literally (case insensitive)
\. matches the character . with index 4610 (2E16 or 568) literally (case insensitive)
254
matches the characters 254 literally (case insensitive)
Non-capturing group
(?:\.\d{1,3}){2}
{2} matches the previous token exactly 2 times
\. matches the character . with index 4610 (2E16 or 568) literally (case insensitive)
\d
matches a digit (equivalent to [0-9])
{1,3} matches the previous token between 1 and 3 times, as many times as possible, giving back as needed (greedy)
Negative Lookahead
(?!192\.168(?:\.\d{1,3}){2})
Assert that the Regex below does not match
192
matches the characters 192 literally (case insensitive)
\. matches the character . with index 4610 (2E16 or 568) literally (case insensitive)
168
matches the characters 168 literally (case insensitive)
Non-capturing group
(?:\.\d{1,3}){2}
{2} matches the previous token exactly 2 times
\. matches the character . with index 4610 (2E16 or 568) literally (case insensitive)
\d
matches a digit (equivalent to [0-9])
{1,3} matches the previous token between 1 and 3 times, as many times as possible, giving back as needed (greedy)
Negative Lookahead
(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})
Assert that the Regex below does not match
172
matches the characters 172 literally (case insensitive)
\. matches the character . with index 4610 (2E16 or 568) literally (case insensitive)
Non-capturing group
(?:1[6-9]|2\d|3[0-1])
1st Alternative
1[6-9]
1 matches the character 1 with index 4910 (3116 or 618) literally (case insensitive)
Match a single character present in the list below
[6-9]
6-9 matches a single character in the range between 6 (index 54) and 9 (index 57) (case insensitive)
2nd Alternative
2\d
2 matches the character 2 with index 5010 (3216 or 628) literally (case insensitive)
\d matches a digit (equivalent to [0-9])
3rd Alternative
3[0-1]
3 matches the character 3 with index 5110 (3316 or 638) literally (case insensitive)
Match a single character present in the list below
[0-1]
0-1 matches a single character in the range between 0 (index 48) and 1 (index 49) (case insensitive)
Non-capturing group
(?:\.\d{1,3}){2}
{2} matches the previous token exactly 2 times
\. matches the character . with index 4610 (2E16 or 568) literally (case insensitive)
\d
matches a digit (equivalent to [0-9])
{1,3} matches the previous token between 1 and 3 times, as many times as possible, giving back as needed (greedy)
Non-capturing group
(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])
1st Alternative
[1-9]\d?
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 insensitive)
\d
matches a digit (equivalent to [0-9])
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
2nd Alternative
1\d\d
1 matches the character 1 with index 4910 (3116 or 618) literally (case insensitive)
\d matches a digit (equivalent to [0-9])
\d matches a digit (equivalent to [0-9])
3rd Alternative
2[01]\d
2 matches the character 2 with index 5010 (3216 or 628) literally (case insensitive)
Match a single character present in the list below
[01]
01
matches a single character in the list 01 (case insensitive)
\d matches a digit (equivalent to [0-9])
4th Alternative
22[0-3]
22
matches the characters 22 literally (case insensitive)
Match a single character present in the list below
[0-3]
Non-capturing group
(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}
{2} matches the previous token exactly 2 times
\. matches the character . with index 4610 (2E16 or 568) literally (case insensitive)
Non-capturing group
(?:1?\d{1,2}|2[0-4]\d|25[0-5])
1st Alternative
1?\d{1,2}
1
matches the character 1 with index 4910 (3116 or 618) literally (case insensitive)
\d
matches a digit (equivalent to [0-9])
{1,2} matches the previous token between 1 and 2 times, as many times as possible, giving back as needed (greedy)
2nd Alternative
2[0-4]\d
2 matches the character 2 with index 5010 (3216 or 628) literally (case insensitive)
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 insensitive)
\d matches a digit (equivalent to [0-9])
3rd Alternative
25[0-5]
25
matches the characters 25 literally (case insensitive)
Match a single character present in the list below
[0-5]
Non-capturing group
(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))
\. matches the character . with index 4610 (2E16 or 568) literally (case insensitive)
Non-capturing group
(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4])
1st Alternative
[1-9]\d?
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 insensitive)
\d
matches a digit (equivalent to [0-9])
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
2nd Alternative
1\d\d
1 matches the character 1 with index 4910 (3116 or 618) literally (case insensitive)
\d matches a digit (equivalent to [0-9])
\d matches a digit (equivalent to [0-9])
3rd Alternative
2[0-4]\d
4th Alternative
25[0-4]
2nd Alternative
(?:(?:[a-z\x{00a1}-\x{ffff}0-9]+-?)*[a-z\x{00a1}-\x{ffff}0-9]+)(?:\.(?:[a-z\x{00a1}-\x{ffff}0-9]+-?)*[a-z\x{00a1}-\x{ffff}0-9]+)*(?:\.(?:[a-z\x{00a1}-\x{ffff}]{2,}))
Non-capturing group
(?:(?:[a-z\x{00a1}-\x{ffff}0-9]+-?)*[a-z\x{00a1}-\x{ffff}0-9]+)
Non-capturing group
(?:[a-z\x{00a1}-\x{ffff}0-9]+-?)*
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
Match a single character present in the list below
[a-z\x{00a1}-\x{ffff}0-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 insensitive)
\x{00a1}-\x{ffff} matches a single character in the range between ¡ (index 161) and ￿ (index 65535) (case insensitive)
0-9 matches a single character in the range between 0 (index 48) and 9 (index 57) (case insensitive)
-
matches the character - with index 4510 (2D16 or 558) literally (case insensitive)
Match a single character present in the list below
[a-z\x{00a1}-\x{ffff}0-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 insensitive)
\x{00a1}-\x{ffff} matches a single character in the range between ¡ (index 161) and ￿ (index 65535) (case insensitive)
0-9 matches a single character in the range between 0 (index 48) and 9 (index 57) (case insensitive)
Non-capturing group
(?:\.(?:[a-z\x{00a1}-\x{ffff}0-9]+-?)*[a-z\x{00a1}-\x{ffff}0-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 insensitive)
Non-capturing group
(?:[a-z\x{00a1}-\x{ffff}0-9]+-?)*
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
Match a single character present in the list below
[a-z\x{00a1}-\x{ffff}0-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 insensitive)
\x{00a1}-\x{ffff} matches a single character in the range between ¡ (index 161) and ￿ (index 65535) (case insensitive)
0-9 matches a single character in the range between 0 (index 48) and 9 (index 57) (case insensitive)
-
matches the character - with index 4510 (2D16 or 558) literally (case insensitive)
Match a single character present in the list below
[a-z\x{00a1}-\x{ffff}0-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 insensitive)
\x{00a1}-\x{ffff} matches a single character in the range between ¡ (index 161) and ￿ (index 65535) (case insensitive)
0-9 matches a single character in the range between 0 (index 48) and 9 (index 57) (case insensitive)
Non-capturing group
(?:\.(?:[a-z\x{00a1}-\x{ffff}]{2,}))
\. matches the character . with index 4610 (2E16 or 568) literally (case insensitive)
Non-capturing group
(?:[a-z\x{00a1}-\x{ffff}]{2,})
Match a single character present in the list below
[a-z\x{00a1}-\x{ffff}]
{2,} matches the previous token between 2 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 insensitive)
\x{00a1}-\x{ffff} matches a single character in the range between ¡ (index 161) and ￿ (index 65535) (case insensitive)
Non-capturing group
(?::\d{2,5})?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
: matches the character : with index 5810 (3A16 or 728) literally (case insensitive)
\d
matches a digit (equivalent to [0-9])
{2,5} matches the previous token between 2 and 5 times, as many times as possible, giving back as needed (greedy)
Non-capturing group
(?:\/[^\s]*)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
\/ matches the character / with index 4710 (2F16 or 578) literally (case insensitive)
Match a single character not present in the list below
[^\s]
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
\s matches any whitespace character (equivalent to [\r\n\t\f\v ])
\b assert position at a word boundary: (^\w|\w$|\W\w|\w\W)
Global pattern flags
g modifier: global. All matches (don't return after first match)
i modifier: insensitive. Case insensitive match (ignores case of [a-zA-Z])
Your regular expression does not match the subject string.Try launching the debugger to find out why.

Regular Expression
No Match

/
/
gi

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.