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
"
(?xs)<tr>[^<]*?<td.*?>(.*?)</.*? <td.*?>.*?(?#skip second col) <td.*?>(?:<.*?>)+?((?:(?!<).)*)(?:<.*?>)+?</td.*? <td.*?>(.*?)</.*? id=([0-9]+)
"
g
(?xs)
match the remainder of the pattern with the following effective flags: gxs
x modifier: extended. Spaces and text after a # in the pattern are ignored
s modifier: single line. Dot matches newline characters
<tr>
matches the characters <tr> literally (case sensitive)
Match a single character not present in the list below
[^<]
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
< matches the character < with index 6010 (3C16 or 748) literally (case sensitive)
<td
matches the characters <td literally (case sensitive)
.
matches any character
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
> matches the character > with index 6210 (3E16 or 768) literally (case sensitive)
1st Capturing Group
(.*?)
.
matches any character
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
</
matches the characters </ literally (case sensitive)
.
matches any character
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
<td
matches the characters <td literally (case sensitive)
.
matches any character
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
> matches the character > with index 6210 (3E16 or 768) literally (case sensitive)
.
matches any character
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
Comment: skip second col
<td
matches the characters <td literally (case sensitive)
.
matches any character
> matches the character > with index 6210 (3E16 or 768) literally (case sensitive)
Non-capturing group
(?:<.*?>)+?
2nd Capturing Group
((?:(?!<).)*)
Non-capturing group
(?:<.*?>)+?
</td
matches the characters </td literally (case sensitive)
.
matches any character
<td
matches the characters <td literally (case sensitive)
.
matches any character
> matches the character > with index 6210 (3E16 or 768) literally (case sensitive)
3rd Capturing Group
(.*?)
</
matches the characters </ literally (case sensitive)
.
matches any character
id=
matches the characters id= literally (case sensitive)
4th Capturing Group
([0-9]+)
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

r"
"
g

Test String