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
"
<tr class='(.)'><td class='TR(.)'><a href='http://www\.openstreetmap\.org\/\?mlon=([-\d\.]+)&mlat=([-\d\.]+)&zoom=\d+' target='_blank'><img src='img\/flags\/(\w+)\.gif' class='flag' width='\d+px' title='(.+)' alt='\w+' border='0'><\/a>&nbsp;<a href='router_detail\.php\?FP=([a-zA-Z0-9]+)' target='_blank'>([^\<]+)<\/a><\/td><td class='TDb'><table cellspacing='0' cellpadding='0' class='bwb'><tr title='([^']+)'><td class='bwr.?'><img src='img/bar/\d+.png' width='\d+px' height='15px' alt='\d+'></td><td>&nbsp;<small>&nbsp;\d+</small></td></tr></table></td><td class='TDc.?'>([^<]+)</td><td class='TDS'><table class='iT'><tr><td class='iT'>([^\[]+)\[<a class='who' href='/cgi\-bin/whois.pl\?ip=[\d\.]+' target='_blank'>([\d\.]+)</a>\]</td>(<td><img src='img/status/Fast.png' title='Fast Server' alt='Fast Server'></td>)?(<td><img src='img/status/Exit.png' title='Exit Server' alt='Exit Server'></td>)?(<td><img src='img/status/Dir.png' title='Directory Server' alt='Directory Server'></td>)?(<td><img src='img/status/Guard.png' title='Guard Server' alt='Guard Server'></td>)?(<td><img src='img/status/Stable.png' title='Stable Server' alt='Stable Server'></td>)?(<td><img src='img/status/Authority.png' title='Authority Server' alt='Authority Server'/></td>)?<td><img src='[^']+' title='([^']+)' alt='[^']+'></td>(<td><img src='[^']+' title='([^']*)' alt='[^']*'></td>)?</tr></table></td><td class='TDc'>(<b>)?(\d*)(</b>)?</td><td class='TDc'>(<b>)?([None\d]*)(</b>)?</td><td class='(F\d)'></td></tr>
"
g
<tr class='
matches the characters <tr class=' literally (case sensitive)
1st Capturing Group
(.)
. matches any character (except for line terminators)
'><td class='TR
matches the characters '><td class='TR literally (case sensitive)
2nd Capturing Group
(.)
. matches any character (except for line terminators)
'><a href='http://www
matches the characters '><a href='http://www literally (case sensitive)
\. matches the character . with index 4610 (2E16 or 568) literally (case sensitive)
openstreetmap
matches the characters openstreetmap literally (case sensitive)
\. matches the character . with index 4610 (2E16 or 568) literally (case sensitive)
org
matches the characters org literally (case sensitive)
\/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
\? matches the character ? with index 6310 (3F16 or 778) literally (case sensitive)
mlon=
matches the characters mlon= literally (case sensitive)
3rd Capturing Group
([-\d\.]+)
Match a single character present in the list below
[-\d\.]
+ 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)
\d matches a digit (equivalent to [0-9])
\. matches the character . with index 4610 (2E16 or 568) literally (case sensitive)
&mlat=
matches the characters &mlat= literally (case sensitive)
4th Capturing Group
([-\d\.]+)
Match a single character present in the list below
[-\d\.]
+ 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)
\d matches a digit (equivalent to [0-9])
\. matches the character . with index 4610 (2E16 or 568) literally (case sensitive)
&zoom=
matches the characters &zoom= literally (case sensitive)
\d
matches a digit (equivalent to [0-9])
' target='_blank'><img src='img
matches the characters ' target='_blank'><img src='img literally (case sensitive)
\/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
flags
matches the characters flags literally (case sensitive)
\/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
5th Capturing Group
(\w+)
\. matches the character . with index 4610 (2E16 or 568) literally (case sensitive)
gif' class='flag' width='
matches the characters gif' class='flag' width=' literally (case sensitive)
\d
matches a digit (equivalent to [0-9])
px' title='
matches the characters px' title=' literally (case sensitive)
6th Capturing Group
(.+)
' alt='
matches the characters ' alt=' literally (case sensitive)
\w
matches any word character (equivalent to [a-zA-Z0-9_])
' border='0'><
matches the characters ' border='0'>< literally (case sensitive)
\/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
a>&nbsp;<a href='router_detail
matches the characters a>&nbsp;<a href='router_detail literally (case sensitive)
\. matches the character . with index 4610 (2E16 or 568) literally (case sensitive)
php
matches the characters php literally (case sensitive)
\? matches the character ? with index 6310 (3F16 or 778) literally (case sensitive)
FP=
matches the characters FP= literally (case sensitive)
7th Capturing Group
([a-zA-Z0-9]+)
' target='_blank'>
matches the characters ' target='_blank'> literally (case sensitive)
8th Capturing Group
([^\<]+)
< matches the character < with index 6010 (3C16 or 748) literally (case sensitive)
\/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
a><
matches the characters a>< literally (case sensitive)
\/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
td><td class='TDb'><table cellspacing='0' cellpadding='0' class='bwb'><tr title='
matches the characters td><td class='TDb'><table cellspacing='0' cellpadding='0' class='bwb'><tr title=' literally (case sensitive)
9th Capturing Group
([^']+)
'><td class='bwr
matches the characters '><td class='bwr literally (case sensitive)
.
matches any character (except for line terminators)
'><img src='img/bar/
matches the characters '><img src='img/bar/ literally (case sensitive)
\d
matches a digit (equivalent to [0-9])
. matches any character (except for line terminators)
png' width='
matches the characters png' width=' literally (case sensitive)
\d
matches a digit (equivalent to [0-9])
px' height='15px' alt='
matches the characters px' height='15px' alt=' literally (case sensitive)
\d
matches a digit (equivalent to [0-9])
'></td><td>&nbsp;<small>&nbsp;
matches the characters '></td><td>&nbsp;<small>&nbsp; literally (case sensitive)
\d
matches a digit (equivalent to [0-9])
</small></td></tr></table></td><td class='TDc
matches the characters </small></td></tr></table></td><td class='TDc literally (case sensitive)
.
matches any character (except for line terminators)
'>
matches the characters '> literally (case sensitive)
10th Capturing Group
([^<]+)
</td><td class='TDS'><table class='iT'><tr><td class='iT'>
matches the characters </td><td class='TDS'><table class='iT'><tr><td class='iT'> literally (case sensitive)
11th Capturing Group
([^\[]+)
\[ matches the character [ with index 9110 (5B16 or 1338) literally (case sensitive)
<a class='who' href='/cgi
matches the characters <a class='who' href='/cgi literally (case sensitive)
\- matches the character - with index 4510 (2D16 or 558) literally (case sensitive)
bin/whois
matches the characters bin/whois literally (case sensitive)
. matches any character (except for line terminators)
pl
matches the characters pl literally (case sensitive)
\? matches the character ? with index 6310 (3F16 or 778) literally (case sensitive)
ip=
matches the characters ip= literally (case sensitive)
Match a single character present in the list below
[\d\.]
' target='_blank'>
matches the characters ' target='_blank'> literally (case sensitive)
12th Capturing Group
([\d\.]+)
</a>
matches the characters </a> literally (case sensitive)
\] matches the character ] with index 9310 (5D16 or 1358) literally (case sensitive)
</td>
matches the characters </td> literally (case sensitive)
13th Capturing Group
(<td><img src='img/status/Fast.png' title='Fast Server' alt='Fast Server'></td>)?
14th Capturing Group
(<td><img src='img/status/Exit.png' title='Exit Server' alt='Exit Server'></td>)?
15th Capturing Group
(<td><img src='img/status/Dir.png' title='Directory Server' alt='Directory Server'></td>)?
16th Capturing Group
(<td><img src='img/status/Guard.png' title='Guard Server' alt='Guard Server'></td>)?
17th Capturing Group
(<td><img src='img/status/Stable.png' title='Stable Server' alt='Stable Server'></td>)?
18th Capturing Group
(<td><img src='img/status/Authority.png' title='Authority Server' alt='Authority Server'/></td>)?
<td><img src='
matches the characters <td><img src=' literally (case sensitive)
Match a single character not present in the list below
[^']
' title='
matches the characters ' title=' literally (case sensitive)
19th Capturing Group
([^']+)
' alt='
matches the characters ' alt=' literally (case sensitive)
Match a single character not present in the list below
[^']
'></td>
matches the characters '></td> literally (case sensitive)
20th Capturing Group
(<td><img src='[^']+' title='([^']*)' alt='[^']*'></td>)?
</tr></table></td><td class='TDc'>
matches the characters </tr></table></td><td class='TDc'> literally (case sensitive)
22nd Capturing Group
(<b>)?
23rd Capturing Group
(\d*)
24th Capturing Group
(</b>)?
</td><td class='TDc'>
matches the characters </td><td class='TDc'> literally (case sensitive)
25th Capturing Group
(<b>)?
26th Capturing Group
([None\d]*)
27th Capturing Group
(</b>)?
</td><td class='
matches the characters </td><td class=' literally (case sensitive)
28th Capturing Group
(F\d)
'></td></tr>
matches the characters '></td></tr> 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

r"
"
g

Test String