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
`
((2[0-4]\d|25[0-5]|1\d\d|0\d\d|0\d|\d\d|\d)[\.]){3}(2[0-4]\d|25[0-5]|1\d\d|0\d\d|0\d|\d\d|\d)|(((\w*)://(www)*)\.*((\w*-*\w*)\.)*(\w*)(:\d+)*/*#*(/*)(\w+/)*(\w*\$*\w*\,*\w*\?*=*)*\.*(\w*))|((www\.)*(\w+-*)(\.\w+)+)(:\d+)*/*#*(/*)(\w+/)*(\w*\$*\w*\,*\w*\?*=*)*\.*(\w*)
`
gm
1st Alternative
((2[0-4]\d|25[0-5]|1\d\d|0\d\d|0\d|\d\d|\d)[\.]){3}(2[0-4]\d|25[0-5]|1\d\d|0\d\d|0\d|\d\d|\d)
1st Capturing Group
((2[0-4]\d|25[0-5]|1\d\d|0\d\d|0\d|\d\d|\d)[\.]){3}
{3} matches the previous token exactly 3 times
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
2nd Capturing Group
(2[0-4]\d|25[0-5]|1\d\d|0\d\d|0\d|\d\d|\d)
1st Alternative
2[0-4]\d
2 matches the character 2 with index 5010 (3216 or 628) 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)
\d matches a digit (equivalent to [0-9])
2nd Alternative
25[0-5]
25
matches the characters 25 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)
3rd Alternative
1\d\d
1 matches the character 1 with index 4910 (3116 or 618) literally (case sensitive)
\d matches a digit (equivalent to [0-9])
\d matches a digit (equivalent to [0-9])
4th Alternative
0\d\d
0 matches the character 0 with index 4810 (3016 or 608) literally (case sensitive)
\d matches a digit (equivalent to [0-9])
\d matches a digit (equivalent to [0-9])
5th Alternative
0\d
0 matches the character 0 with index 4810 (3016 or 608) literally (case sensitive)
\d matches a digit (equivalent to [0-9])
6th Alternative
\d\d
\d matches a digit (equivalent to [0-9])
\d matches a digit (equivalent to [0-9])
7th Alternative
\d
\d matches a digit (equivalent to [0-9])
Match a single character present in the list below
[\.]
\. matches the character . with index 4610 (2E16 or 568) literally (case sensitive)
3rd Capturing Group
(2[0-4]\d|25[0-5]|1\d\d|0\d\d|0\d|\d\d|\d)
1st Alternative
2[0-4]\d
2 matches the character 2 with index 5010 (3216 or 628) 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)
\d matches a digit (equivalent to [0-9])
2nd Alternative
25[0-5]
25
matches the characters 25 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)
3rd Alternative
1\d\d
1 matches the character 1 with index 4910 (3116 or 618) literally (case sensitive)
\d matches a digit (equivalent to [0-9])
\d matches a digit (equivalent to [0-9])
4th Alternative
0\d\d
0 matches the character 0 with index 4810 (3016 or 608) literally (case sensitive)
\d matches a digit (equivalent to [0-9])
\d matches a digit (equivalent to [0-9])
5th Alternative
0\d
0 matches the character 0 with index 4810 (3016 or 608) literally (case sensitive)
\d matches a digit (equivalent to [0-9])
6th Alternative
\d\d
\d matches a digit (equivalent to [0-9])
\d matches a digit (equivalent to [0-9])
7th Alternative
\d
\d matches a digit (equivalent to [0-9])
2nd Alternative
(((\w*)://(www)*)\.*((\w*-*\w*)\.)*(\w*)(:\d+)*/*#*(/*)(\w+/)*(\w*\$*\w*\,*\w*\?*=*)*\.*(\w*))
4th Capturing Group
(((\w*)://(www)*)\.*((\w*-*\w*)\.)*(\w*)(:\d+)*/*#*(/*)(\w+/)*(\w*\$*\w*\,*\w*\?*=*)*\.*(\w*))
5th Capturing Group
((\w*)://(www)*)
6th Capturing Group
(\w*)
\w
matches any word character (equivalent to [a-zA-Z0-9_])
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
://
matches the characters :// literally (case sensitive)
7th Capturing Group
(www)*
* 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
www
matches the characters www literally (case sensitive)
\.
matches the character . with index 4610 (2E16 or 568) literally (case sensitive)
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
8th Capturing Group
((\w*-*\w*)\.)*
* 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
9th Capturing Group
(\w*-*\w*)
\w
matches any word character (equivalent to [a-zA-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 4510 (2D16 or 558) literally (case sensitive)
\w
matches any word character (equivalent to [a-zA-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)
10th Capturing Group
(\w*)
\w
matches any word character (equivalent to [a-zA-Z0-9_])
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
11th Capturing Group
(:\d+)*
* 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 5810 (3A16 or 728) literally (case sensitive)
\d
matches a digit (equivalent to [0-9])
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
/
matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
#
matches the character # with index 3510 (2316 or 438) literally (case sensitive)
12th Capturing Group
(/*)
/
matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
13th Capturing Group
(\w+/)*
* 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
\w
matches any word character (equivalent to [a-zA-Z0-9_])
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
14th Capturing Group
(\w*\$*\w*\,*\w*\?*=*)*
* 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
\w
matches any word character (equivalent to [a-zA-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 3610 (2416 or 448) literally (case sensitive)
\w
matches any word character (equivalent to [a-zA-Z0-9_])
\,
matches the character , with index 4410 (2C16 or 548) literally (case sensitive)
\w
matches any word character (equivalent to [a-zA-Z0-9_])
\?
matches the character ? with index 6310 (3F16 or 778) literally (case sensitive)
=
matches the character = with index 6110 (3D16 or 758) literally (case sensitive)
\.
matches the character . with index 4610 (2E16 or 568) literally (case sensitive)
15th Capturing Group
(\w*)
3rd Alternative
((www\.)*(\w+-*)(\.\w+)+)(:\d+)*/*#*(/*)(\w+/)*(\w*\$*\w*\,*\w*\?*=*)*\.*(\w*)
16th Capturing Group
((www\.)*(\w+-*)(\.\w+)+)
17th Capturing Group
(www\.)*
* 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
www
matches the characters www literally (case sensitive)
\. matches the character . with index 4610 (2E16 or 568) literally (case sensitive)
18th Capturing Group
(\w+-*)
\w
matches any word character (equivalent to [a-zA-Z0-9_])
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
-
matches the character - with index 4510 (2D16 or 558) literally (case sensitive)
19th Capturing Group
(\.\w+)+
+ 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
\. matches the character . with index 4610 (2E16 or 568) literally (case sensitive)
\w
matches any word character (equivalent to [a-zA-Z0-9_])
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
20th Capturing Group
(:\d+)*
* 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 5810 (3A16 or 728) literally (case sensitive)
\d
matches a digit (equivalent to [0-9])
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
/
matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
#
matches the character # with index 3510 (2316 or 438) literally (case sensitive)
21st Capturing Group
(/*)
/
matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
22nd Capturing Group
(\w+/)*
* 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
\w
matches any word character (equivalent to [a-zA-Z0-9_])
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
23rd Capturing Group
(\w*\$*\w*\,*\w*\?*=*)*
* 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
\w
matches any word character (equivalent to [a-zA-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 3610 (2416 or 448) literally (case sensitive)
* matches the previous token between zero 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 previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
\,
matches the character , with index 4410 (2C16 or 548) literally (case sensitive)
\w
matches any word character (equivalent to [a-zA-Z0-9_])
\?
matches the character ? with index 6310 (3F16 or 778) literally (case sensitive)
=
matches the character = with index 6110 (3D16 or 758) literally (case sensitive)
\.
matches the character . with index 4610 (2E16 or 568) literally (case sensitive)
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
24th Capturing Group
(\w*)
\w
matches any word character (equivalent to [a-zA-Z0-9_])
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
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