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
`
(src="cid:).*?(.+?(\.gif|\.png|\.jpg))+?([^"]*)
`
g
1st Capturing Group
(src="cid:)
src="cid:
matches the characters src="cid: literally (case sensitive)
.
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)
2nd Capturing Group
(.+?(\.gif|\.png|\.jpg))+?
+? matches the previous token between one and unlimited times, as few times as possible, expanding as needed (lazy)
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 any character (except for line terminators)
+? matches the previous token between one and unlimited times, as few times as possible, expanding as needed (lazy)
3rd Capturing Group
(\.gif|\.png|\.jpg)
1st Alternative
\.gif
\. matches the character . with index 4610 (2E16 or 568) literally (case sensitive)
gif
matches the characters gif literally (case sensitive)
2nd Alternative
\.png
\. matches the character . with index 4610 (2E16 or 568) literally (case sensitive)
png
matches the characters png literally (case sensitive)
3rd Alternative
\.jpg
\. matches the character . with index 4610 (2E16 or 568) literally (case sensitive)
jpg
matches the characters jpg literally (case sensitive)
4th Capturing Group
([^"]*)
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 3410 (2216 or 428) literally (case sensitive)
Global pattern flags
g modifier: global. All matches (don't return after first match)
Your regular expression does not match the subject string.

Regular Expression
No Match

`
`
g

Test String