Regular Expressions 101

Save & Share

Flavor

  • PCRE2 (PHP >=7.3)
  • PCRE (PHP <7.3)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java 8
  • .NET 7.0 (C#)
  • Rust
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests

Tools

Sponsors
There are currently no sponsors. Become a sponsor today!
An explanation of your regex will be automatically generated as you type.
Detailed match information will be displayed here automatically.
  • All Tokens
  • Common Tokens
  • General Tokens
  • Anchors
  • Meta Sequences
  • Quantifiers
  • Group Constructs
  • Character Classes
  • Flags/Modifiers
  • Substitution
  • A single character of: a, b or c
    [abc]
  • A character except: a, b or c
    [^abc]
  • A character in the range: a-z
    [a-z]
  • A character not in the range: a-z
    [^a-z]
  • A character in the range: a-z or A-Z
    [a-zA-Z]
  • Any single character
    .
  • Alternate - match either a or b
    a|b
  • Any whitespace character
    \s
  • Any non-whitespace character
    \S
  • Any digit
    \d
  • Any non-digit
    \D
  • Any word character
    \w
  • Any non-word character
    \W
  • Non-capturing group
    (?:...)
  • Capturing group
    (...)
  • Zero or one of a
    a?
  • Zero or more of a
    a*
  • One or more of a
    a+
  • Exactly 3 of a
    a{3}
  • 3 or more of a
    a{3,}
  • Between 3 and 6 of a
    a{3,6}
  • Start of string
    ^
  • End of string
    $
  • A word boundary
    \b
  • Non-word boundary
    \B

Regular Expression
No Match

/
/
gmi

Test String

Code Generator

Generated Code

const regex = /(<)[^<]+?(?=(facebook\.com))[^]+?(\/a>)/gmi; // Alternative syntax using RegExp constructor // const regex = new RegExp('(<)[^<]+?(?=(facebook\\.com))[^]+?(\\\/a>)', 'gmi') const str = `<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"> <head> <meta http-equiv="Content-Type" content="text/html; charset=us-ascii"> <meta name="Generator" content="Microsoft Word 14 (filtered medium)"> <!--[if !mso]><style>v\\:* {behavior:url(#default#VML);} o\\:* {behavior:url(#default#VML);} w\\:* {behavior:url(#default#VML);} .shape {behavior:url(#default#VML);} </style><![endif]--><style><!-- /* Font Definitions */ @font-face {font-family:Wingdings; panose-1:5 0 0 0 0 0 0 0 0 0;} @font-face {font-family:Wingdings; panose-1:5 0 0 0 0 0 0 0 0 0;} @font-face {font-family:Calibri; panose-1:2 15 5 2 2 2 4 3 2 4;} @font-face {font-family:Tahoma; panose-1:2 11 6 4 3 5 4 4 2 4;} @font-face {font-family:"Arial Black"; panose-1:2 11 10 4 2 1 2 2 2 4;} @font-face {font-family:Georgia; panose-1:2 4 5 2 5 4 5 2 3 3;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {margin:0cm; margin-bottom:.0001pt; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-fareast-language:EN-US;} a:link, span.MsoHyperlink {mso-style-priority:99; color:blue; text-decoration:underline;} a:visited, span.MsoHyperlinkFollowed {mso-style-priority:99; color:purple; text-decoration:underline;} p {mso-style-priority:99; mso-margin-top-alt:auto; margin-right:0cm; mso-margin-bottom-alt:auto; margin-left:0cm; font-size:12.0pt; font-family:"Times New Roman","serif";} span.EmailStyle17 {mso-style-type:personal; font-family:"Georgia","serif"; color:windowtext;} span.EmailStyle20 {mso-style-type:personal-reply; font-family:"Calibri","sans-serif"; color:#1F497D;} .MsoChpDefault {mso-style-type:export-only; font-size:10.0pt;} @page WordSection1 {size:612.0pt 792.0pt; margin:72.0pt 72.0pt 72.0pt 72.0pt;} div.WordSection1 {page:WordSection1;} --></style><!--[if gte mso 9]><xml> <o:shapedefaults v:ext="edit" spidmax="1026" /> </xml><![endif]--><!--[if gte mso 9]><xml> <o:shapelayout v:ext="edit"> <o:idmap v:ext="edit" data="1" /> </o:shapelayout></xml><![endif]--> </head> <body lang="EN-AU" link="blue" vlink="purple"> <!--ppd39--><!--ppd37--> <div class="WordSection1"> <p class="MsoNormal"><span style="color:#1F497D">Testing what we can do with the footers.<o:p></o:p></span></p> <p class="MsoNormal"><span style="color:#1F497D"><o:p>&nbsp;</o:p></span></p> <p class="MsoNormal"><span style="color:#1F497D"><a href="Http://mail.google.com">Http://mail.google.com</a><o:p></o:p></span></p> <p class="MsoNormal"><span style="color:#1F497D"><o:p>&nbsp;</o:p></span></p> <p class="MsoNormal"><span style="color:#1F497D">That was a link<o:p></o:p></span></p> <p class="MsoNormal"><span style="color:#1F497D"><o:p>&nbsp;</o:p></span></p> <p class="MsoNormal"><span style="color:#1F497D"><o:p>&nbsp;</o:p></span></p> <div><br> <br> <span id="ppe_37"> <div align="left"> <p><font size="2" face="Arial"><strong><font color="black">Russell Miller</font><br> <font color="black"></font>&nbsp;<br> </strong></font><font color="#c0c0c0" size="2" face="Arial Black">P</font>&nbsp; <font size="2" face="Arial"> <font color="black"></font><font color="black"></font>&nbsp; </font><font color="#c0c0c0" size="2" face="Arial Black">F</font>&nbsp; <font size="2" face="Arial"><font color="#000000" face="Arial"><br> &nbsp;&nbsp; <br> Brisbane QLD 4170&nbsp; </font>&nbsp;<br> <span><font color="#c0c0c0" face="Arial Black">E </font><a href="mailto:R.Miller@endeavour.com.au"><font color="#000000" size="2" face="Arial">R.Miller@endeavour.com.au</font></a>&nbsp;&nbsp; <font color="#c0c0c0" size="2" face="Arial Black">W <a href="http://www.endeavour.com.au/"> <font color="#000000" face="Arial">www.endeavour.com.au</font></a></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="https://www.qld.gov.au/about/events-awards-honours/awards/qld-greats-awards/"> <img border="0" src="http://www.endeavour.com.au/~/media/Images/EmailSignature/email-qld-greats-recognition-mark.ashx"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="https://www.facebook.com/endeavourfoundation"><img border="0" src="http://www.endeavour.com.au/~/media/Images/EmailSignature/facebook.ashx"></a><br> <br> <a href="https://www.facebook.com/pages/The-Labels-Shop/1416142462035315?ref=ts&amp;fref=ts"><img border="0" src="http://www.endeavour.com.au/~/media/Images/EmailSignature/Labels-Shop-Email-Signature"> </a></span></font></p> </div> </span> <div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm"> <p class="MsoNormal"><b><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;;mso-fareast-language:EN-AU">From:</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;;mso-fareast-language:EN-AU"> Yvette Gorlee <br> <b>Sent:</b> Tuesday, 2 June 2015 11:03 AM<br> <b>To:</b> Russell Miller<br> <b>Subject:</b> Missing Address in Location<o:p></o:p></span></p> </div> </div> <p class="MsoNormal"><o:p>&nbsp;</o:p></p> <p class="MsoNormal"><span style="font-family:&quot;Georgia&quot;,&quot;serif&quot;">Hi Russell<o:p></o:p></span></p> <p class="MsoNormal"><span style="font-family:&quot;Georgia&quot;,&quot;serif&quot;"><o:p>&nbsp;</o:p></span></p> <p class="MsoNormal"><span style="font-family:&quot;Georgia&quot;,&quot;serif&quot;">This is the address missing in the Location Box &#8211; Please add: 1 Westmoreland Street, Rockhampton QLD 4701.&nbsp; <o:p></o:p></span></p> <p class="MsoNormal"><span style="font-family:&quot;Georgia&quot;,&quot;serif&quot;"><o:p>&nbsp;</o:p></span></p> <p class="MsoNormal"><span style="font-family:&quot;Georgia&quot;,&quot;serif&quot;;mso-fareast-language:EN-AU">Thank-you </span><span style="font-family:Wingdings;mso-fareast-language:EN-AU">J</span><span style="font-family:&quot;Georgia&quot;,&quot;serif&quot;;mso-fareast-language:EN-AU"><o:p></o:p></span></p> <p class="MsoNormal"><o:p>&nbsp;</o:p></p> <p class="MsoNormal"><span style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;mso-fareast-language:EN-AU"><br> <br> <br> <o:p></o:p></span></p> <p><strong><span style="font-size:10.0pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;color:black">Yvette Gorlee</span></strong><b><span style="font-size:10.0pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;"><br> <strong><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;color:black">Helpdesk Officer</span></strong><strong><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;"> &nbsp;</span></strong><br> </span></b><span style="font-size:10.0pt;font-family:&quot;Arial Black&quot;,&quot;sans-serif&quot;;color:silver">P</span>&nbsp; <span style="font-size:10.0pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;color:black">(07) 3908 7299</span><span style="font-size:10.0pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;"> &nbsp; </span><span style="font-size:10.0pt;font-family:&quot;Arial Black&quot;,&quot;sans-serif&quot;;color:silver">F</span>&nbsp; <span style="font-size:10.0pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;color:black">(07) 3908 7128<br> 50 Southgate Ave, Cannon Hill QLD 4170&nbsp;&nbsp; <br> PO Box 3555 Tingalpa QLD 4173&nbsp; Australia </span><span style="font-size:10.0pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">&nbsp;<br> </span><span style="font-size:10.0pt;font-family:&quot;Arial Black&quot;,&quot;sans-serif&quot;;color:silver">E </span><span style="font-size:10.0pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;"><a href="mailto:y.gorlee@endeavour.com.au"><span style="color:black">y.gorlee@endeavour.com.au</span></a>&nbsp;&nbsp; </span><span style="font-size:10.0pt;font-family:&quot;Arial Black&quot;,&quot;sans-serif&quot;;color:silver">W <a href="http://www.endeavour.com.au/"><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;color:black">www.endeavour.com.au</span></a></span><span style="font-size:10.0pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="https://www.qld.gov.au/about/events-awards-honours/awards/qld-greats-awards/"> <span style="text-decoration:none"><img border="0" id="_x0000_i1025" src="http://www.endeavour.com.au/~/media/Images/EmailSignature/email-qld-greats-recognition-mark.ashx"></span></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="https://www.facebook.com/endeavourfoundation"><span style="text-decoration:none"><img border="0" id="_x0000_i1026" src="http://www.endeavour.com.au/~/media/Images/EmailSignature/facebook.ashx"></span></a><br> <br> <a href="https://gala.endeavour.com.au"><span style="text-decoration:none"><img border="0" id="_x0000_i1027" src="http://www.endeavour.com.au/~/media/Images/EmailSignature/Anniversary-Gala-Email-Signature"></span></a></span><o:p></o:p></p> </div> <br> <br> <span id="ppe_39"><font color="silver"><span style="FONT-SIZE: 7.5pt; FONT-FAMILY: Verdana; COLOR: gray"><font size="1">Disclaimer - June 2, 2015</font></font></span> <p></p> <font size="1"><font color="gray" face="Verdana"><span style="FONT-SIZE: 7.5pt; FONT-FAMILY: Verdana; COLOR: gray">This email and any files <font size="1">transmitted</font> with it are confidential and intended solely for <strong>endeavourdev@service-now.com</strong></span></font> <font color="gray" face="Verdana"> <span style="FONT-SIZE: 7.5pt; FONT-FAMILY: Verdana; COLOR: gray">. If you are not the named addressee you should not disseminate, distribute, copy or alter this email. Any views or opinions presented in this email are solely those of the author and might not represent those of Endeavour. Warning: Although Endeavour has taken reasonable precautions to ensure no viruses are present in this email, the company cannot accept responsibility for any loss or damage arising from the use of this email or attachments. <p>Endeavour Foundation respects your privacy. All personal information we hold about you is kept confidential, according to Australian privacy law.<br> For more information about Endeavour Foundation and privacy, visit our website &#8211; <a href="http://www.endeavour.com.au"> www.endeavour.com.au</a>.</p> </span></font></font></span> </body> </html>`; // Reset `lastIndex` if this regex is defined globally // regex.lastIndex = 0; let m; while ((m = regex.exec(str)) !== null) { // This is necessary to avoid infinite loops with zero-width matches if (m.index === regex.lastIndex) { regex.lastIndex++; } // The result can be accessed through the `m`-variable. m.forEach((match, groupIndex) => { console.log(`Found match, group ${groupIndex}: ${match}`); }); }

Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions