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((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/?)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\)){0,}(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s\!()\[\]{};:\'\"\.\,<>?«»“”‘’]){0,})
/
i
\b assert position at a word boundary: (^\w|\w$|\W\w|\w\W)
1st Capturing Group
((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/?)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\)){0,}(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s\!()\[\]{};:\'\"\.\,<>?«»“”‘’]){0,})
Non-capturing group
(?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/?)
1st Alternative
[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])
Match a single character present in the list below
[a-z]
a-z matches a single character in the range between a (index 97) and z (index 122) (case insensitive)
Match a single character present in the list below
[\w-]
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
\w matches any word character (equivalent to [a-zA-Z0-9_])
- matches the character - with index 4510 (2D16 or 558) literally (case insensitive)
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 the character : with index 5810 (3A16 or 728) literally (case insensitive)
Non-capturing group
(?:\/{1,3}|[a-z0-9%])
1st Alternative
\/{1,3}
\/
matches the character / with index 4710 (2F16 or 578) literally (case insensitive)
{1,3} matches the previous token between 1 and 3 times, as many times as possible, giving back as needed (greedy)
2nd Alternative
[a-z0-9%]
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 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 3710 (2516 or 458) literally (case insensitive)
2nd Alternative
www\d{0,3}[.]
www
matches the characters www literally (case insensitive)
\d
matches a digit (equivalent to [0-9])
{0,3} matches the previous token between 0 and 3 times, as many times as possible, giving back as needed (greedy)
Match a single character present in the list below
[.]
. matches the character . with index 4610 (2E16 or 568) literally (case insensitive)
3rd Alternative
[a-z0-9.\-]+[.][a-z]{2,4}\/?
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 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 4610 (2E16 or 568) literally (case insensitive)
\- matches the character - with index 4510 (2D16 or 558) literally (case insensitive)
Match a single character present in the list below
[.]
. matches the character . with index 4610 (2E16 or 568) literally (case insensitive)
Match a single character present in the list below
[a-z]
{2,4} matches the previous token between 2 and 4 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)
\/
matches the character / with index 4710 (2F16 or 578) literally (case insensitive)
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
Non-capturing group
(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\)){0,}
{0,} matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
1st Alternative
[^\s()<>]+
Match a single character not present in the list below
[^\s()<>]
+ matches the previous token between one 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 \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
()<>
matches a single character in the list ()<> (case insensitive)
2nd Alternative
\(([^\s()<>]+|(\([^\s()<>]+\)))*\)
\( matches the character ( with index 4010 (2816 or 508) literally (case insensitive)
2nd Capturing Group
([^\s()<>]+|(\([^\s()<>]+\)))*
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
A repeated capturing group will only capture the last iteration. Put a capturing group around the repeated group to capture all iterations or use a non-capturing group instead if you're not interested in the data
1st Alternative
[^\s()<>]+
Match a single character not present in the list below
[^\s()<>]
+ matches the previous token between one 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 \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
()<>
matches a single character in the list ()<> (case insensitive)
2nd Alternative
(\([^\s()<>]+\))
3rd Capturing Group
(\([^\s()<>]+\))
\( matches the character ( with index 4010 (2816 or 508) literally (case insensitive)
Match a single character not present in the list below
[^\s()<>]
+ matches the previous token between one 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 \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
()<>
matches a single character in the list ()<> (case insensitive)
\) matches the character ) with index 4110 (2916 or 518) literally (case insensitive)
\) matches the character ) with index 4110 (2916 or 518) literally (case insensitive)
Non-capturing group
(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s\!()\[\]{};:\'\"\.\,<>?«»“”‘’]){0,}
{0,} matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
1st Alternative
\(([^\s()<>]+|(\([^\s()<>]+\)))*\)
\( matches the character ( with index 4010 (2816 or 508) literally (case insensitive)
4th Capturing Group
([^\s()<>]+|(\([^\s()<>]+\)))*
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
A repeated capturing group will only capture the last iteration. Put a capturing group around the repeated group to capture all iterations or use a non-capturing group instead if you're not interested in the data
1st Alternative
[^\s()<>]+
Match a single character not present in the list below
[^\s()<>]
+ matches the previous token between one 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 \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
()<>
matches a single character in the list ()<> (case insensitive)
2nd Alternative
(\([^\s()<>]+\))
5th Capturing Group
(\([^\s()<>]+\))
\( matches the character ( with index 4010 (2816 or 508) literally (case insensitive)
Match a single character not present in the list below
[^\s()<>]
+ matches the previous token between one 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 \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
()<>
matches a single character in the list ()<> (case insensitive)
\) matches the character ) with index 4110 (2916 or 518) literally (case insensitive)
\) matches the character ) with index 4110 (2916 or 518) literally (case insensitive)
2nd Alternative
[^\s\!()\[\]{};:\'\"\.\,<>?«»“”‘’]
Match a single character not present in the list below
[^\s\!()\[\]{};:\'\"\.\,<>?«»“”‘’]
\s matches any whitespace character (equivalent to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
\! matches the character ! with index 3310 (2116 or 418) literally (case insensitive)
()
matches a single character in the list () (case insensitive)
\[ matches the character [ with index 9110 (5B16 or 1338) literally (case insensitive)
\] matches the character ] with index 9310 (5D16 or 1358) literally (case insensitive)
{};:
matches a single character in the list {};: (case insensitive)
\' matches the character ' with index 3910 (2716 or 478) literally (case insensitive)
\" matches the character " with index 3410 (2216 or 428) literally (case insensitive)
\. matches the character . with index 4610 (2E16 or 568) literally (case insensitive)
\, matches the character , with index 4410 (2C16 or 548) literally (case insensitive)
<>?«»“”‘’
matches a single character in the list <>?«»“”‘’ (case insensitive)
Global pattern flags
i modifier: insensitive. Case insensitive match (ignores case of [a-zA-Z])
Your regular expression does not match the subject string.

Regular Expression
No Match

/
/
i

Test String