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
/
((https?|ftp):\/\/)?([a-z0-9+!*(),;?&=.-]+(:[a-z0-9+!*(),;?&=.-]+)?@)?([a-z0-9\-\.]*)\.(([a-z]{2,4})|([0-9]{1,3}\.([0-9]{1,3})\.([0-9]{1,3})))(:[0-9]{2,5})?(\/([a-z0-9+%-]\.?)+)*\/?(\?[a-z+&$_.-][a-z0-9;:@&%=+/.-]*)?(#[a-z_.-][a-z0-9+$%_.-]*)?
/
ig
1st Capturing Group
((https?|ftp):\/\/)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
2nd 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)
3rd 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 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 a single character in the list +!*(),;?&=. (case insensitive)
- 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!
4th Capturing Group
(:[a-z0-9+!*(),;?&=.-]+)?
? 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)
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 a single character in the list +!*(),;?&=. (case insensitive)
- 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 6410 (4016 or 1008) literally (case insensitive)
5th Capturing Group
([a-z0-9\-\.]*)
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 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)
\. matches the character . with index 4610 (2E16 or 568) literally (case insensitive)
\. matches the character . with index 4610 (2E16 or 568) literally (case insensitive)
6th Capturing Group
(([a-z]{2,4})|([0-9]{1,3}\.([0-9]{1,3})\.([0-9]{1,3})))
1st Alternative
([a-z]{2,4})
7th Capturing Group
([a-z]{2,4})
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)
2nd Alternative
([0-9]{1,3}\.([0-9]{1,3})\.([0-9]{1,3}))
8th Capturing Group
([0-9]{1,3}\.([0-9]{1,3})\.([0-9]{1,3}))
Match a single character present in the list below
[0-9]
{1,3} matches the previous token between 1 and 3 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 insensitive)
\. matches the character . with index 4610 (2E16 or 568) literally (case insensitive)
9th Capturing Group
([0-9]{1,3})
Match a single character present in the list below
[0-9]
{1,3} matches the previous token between 1 and 3 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 insensitive)
\. matches the character . with index 4610 (2E16 or 568) literally (case insensitive)
10th Capturing Group
([0-9]{1,3})
Match a single character present in the list below
[0-9]
{1,3} matches the previous token between 1 and 3 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 insensitive)
11th Capturing Group
(:[0-9]{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)
Match a single character present in the list below
[0-9]
{2,5} matches the previous token between 2 and 5 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 insensitive)
12th Capturing Group
(\/([a-z0-9+%-]\.?)+)*
* 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
\/ matches the character / with index 4710 (2F16 or 578) literally (case insensitive)
13th Capturing Group
([a-z0-9+%-]\.?)+
+ matches the previous token between one 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
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 a single character in the list +% (case insensitive)
- 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 4610 (2E16 or 568) literally (case insensitive)
? 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)
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
14th Capturing Group
(\?[a-z+&$_.-][a-z0-9;:@&%=+/.-]*)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
\? matches the character ? with index 6310 (3F16 or 778) literally (case insensitive)
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)
+&$_.
matches a single character in the list +&$_. (case insensitive)
- 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!
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 insensitive)
0-9 matches a single character in the range between 0 (index 48) and 9 (index 57) (case insensitive)
;:@&%=+/.
matches a single character in the list ;:@&%=+/. (case insensitive)
- 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!
15th Capturing Group
(#[a-z_.-][a-z0-9+$%_.-]*)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
# matches the character # with index 3510 (2316 or 438) literally (case insensitive)
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)
_.
matches a single character in the list _. (case insensitive)
- 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!
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 insensitive)
0-9 matches a single character in the range between 0 (index 48) and 9 (index 57) (case insensitive)
+$%_.
matches a single character in the list +$%_. (case insensitive)
- 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!
Global pattern flags
i modifier: insensitive. Case insensitive match (ignores case of [a-zA-Z])
g modifier: global. All matches (don't return after first match)
Your regular expression does not match the subject string.

Regular Expression
No Match

/
/
ig

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 Ruby, please visit: http://ruby-doc.org/core-2.2.0/Regexp.html