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+) (?!(?:href=(["|']+)([http:\/\/])*link\.com([\/])?(.*?)["|'])) *[^>]*>(.*?)[^>]>
/
gm
< matches the character < with index 6010 (3C16 or 748) literally (case sensitive)
1st Capturing Group
(a+)
a
matches the character a with index 9710 (6116 or 1418) literally (case sensitive)
matches the character with index 3210 (2016 or 408) literally (case sensitive)
Negative Lookahead
(?!(?:href=(["|']+)([http:\/\/])*link\.com([\/])?(.*?)["|']))
Assert that the Regex below does not match
Non-capturing group
(?:href=(["|']+)([http:\/\/])*link\.com([\/])?(.*?)["|'])
href=
matches the characters href= literally (case sensitive)
2nd Capturing Group
(["|']+)
Match a single character present in the list below
["|']
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
"|'
matches a single character in the list "|' (case sensitive)
3rd Capturing Group
([http:\/\/])*
* 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
Match a single character present in the list below
[http:\/\/]
http:
matches a single character in the list htp: (case sensitive)
\/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
\/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
link
matches the characters link literally (case sensitive)
\. matches the character . with index 4610 (2E16 or 568) literally (case sensitive)
com
matches the characters com literally (case sensitive)
4th Capturing Group
([\/])?
? 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
[\/]
\/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
5th Capturing Group
(.*?)
.
matches any character (except for line terminators)
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
Match a single character present in the list below
["|']
"|'
matches a single character in the list "|' (case sensitive)
matches the character with index 3210 (2016 or 408) literally (case sensitive)
Match a single character not present in the list below
[^>]
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
> matches the character > with index 6210 (3E16 or 768) literally (case sensitive)
> matches the character > with index 6210 (3E16 or 768) literally (case sensitive)
6th Capturing Group
(.*?)
.
matches any character (except for line terminators)
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
Match a single character not present in the list below
[^>]
> matches the character > with index 6210 (3E16 or 768) literally (case sensitive)
> matches the character > with index 6210 (3E16 or 768) literally (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