Regular Expressions 101

Save & Share

  • Regex Version: ver. 4
  • Update Regex
    ctrl+⇧+s
  • Save new Regex
    ctrl+s
  • Add to Community Library

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

/
/

Test String

Code Generator

Generated Code

const regex = /[-]{14}[0-9]+[\s].+[\s]+.+(?:[\s]*)([\s\S]*)[\s]{3}[-]{14}[0-9]+[\r\n]/; // Alternative syntax using RegExp constructor // const regex = new RegExp('[-]{14}[0-9]+[\\s].+[\\s]+.+(?:[\\s]*)([\\s\\S]*)[\\s]{3}[-]{14}[0-9]+[\\r\\n]', '') const str = `Return-Path: <crown@noflem.date> Delivered-To: me@finlaydag33k.nl Received: from web01.01d.eu by web01.01d.eu with LMTP id UKmwFM5cels9EAAAfNQSUA (envelope-from <crown@noflem.date>) for <me@finlaydag33k.nl>; Mon, 20 Aug 2018 08:16:46 +0200 Return-path: <crown@noflem.date> Envelope-to: me@finlaydag33k.nl Delivery-date: Mon, 20 Aug 2018 08:16:46 +0200 Received: from mail by web01.01d.eu with spam-scanned (Exim 4.91) (envelope-from <crown@noflem.date>) id 1frdUb-0001AC-CB for me@finlaydag33k.nl; Mon, 20 Aug 2018 08:16:46 +0200 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on web01.01d.eu X-Spam-Level: **** X-Spam-Status: No, score=4.5 required=5.0 tests=FROMSPACE, HTML_FONT_LOW_CONTRAST,HTML_MESSAGE,RDNS_NONE,T_REMOTE_IMAGE autolearn=no autolearn_force=no version=3.4.1 Received: from [107.174.30.3] (helo=noflem.date) by web01.01d.eu with esmtp (Exim 4.91) (envelope-from <crown@noflem.date>) id 1frdUZ-00019H-Eg for me@finlaydag33k.nl; Mon, 20 Aug 2018 08:16:45 +0200 From: " Roderick" <crown@noflem.date> Date: Mon, 20 Aug 2018 01:09:47 -0500 MIME-Version: 1.0 Subject: Are you a good pilot? Want to become one? To: <me@finlaydag33k.nl> Message-ID: <28mfPO16iDxTxnPJ_jT4Dib_DlNAQCDEUhRyp96JUTE.NNYAMLzX6-vdM1DDpnOXYdmLgAmcdkEMIV3WWEEeguk@noflem.date> Content-Type: multipart/alternative; boundary="------------008794531541259352341780" ReverseDNS: No reverse DNS for mailserver at 107.174.30.3, +100 Spam score SPFCheck: Server passes SPF test, -30 Spam score SpamTally: Final spam score: 70 X-Antivirus-Scanner: Clean mail though you should still use an Antivirus This is a multi-part message in MIME format. --------------008794531541259352341780 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit The Game All Flight Fans Have Been Waiting For Is Finally Here... <http://www.noflem.date/hkeja/swdecr31drvszty/uMiFCMuWqsqv30RUTjAE6Px2MB44CIYCV-1tGaeRefo/WM6pQxTIkSftU5DtI4wCcP0IycM12PFvPUSfrri_ihbttbluOqtE5Iw2qrONQYsKQHByoiINfeymEqrejohHX8wTJ0bjDXyONZolZHjl0g1pQ3tPccZYHRj_FFS_5jpO>The World's Most Realstic Flight Sim <http://www.noflem.date/hkeja/swdecr31drvszty/uMiFCMuWqsqv30RUTjAE6Px2MB44CIYCV-1tGaeRefo/WM6pQxTIkSftU5DtI4wCcP0IycM12PFvPUSfrri_ihbttbluOqtE5Iw2qrONQYsKQHByoiINfeymEqrejohHX8wTJ0bjDXyONZolZHjl0g1pQ3tPccZYHRj_FFS_5jpO> Watch The Amazing Video Demo Below: <http://www.noflem.date/hkeja/swdecr31drvszty/uMiFCMuWqsqv30RUTjAE6Px2MB44CIYCV-1tGaeRefo/WM6pQxTIkSftU5DtI4wCcP0IycM12PFvPUSfrri_ihbttbluOqtE5Iw2qrONQYsKQHByoiINfeymEqrejohHX8wTJ0bjDXyONZolZHjl0g1pQ3tPccZYHRj_FFS_5jpO> ==>Fly Over 200+ Different Aircraft==&gt;Real Controls Based on Real Cockpits! <http://www.noflem.date/hkeja/swdecr31drvszty/uMiFCMuWqsqv30RUTjAE6Px2MB44CIYCV-1tGaeRefo/WM6pQxTIkSftU5DtI4wCcP0IycM12PFvPUSfrri_ihbttbluOqtE5Iw2qrONQYsKQHByoiINfeymEqrejohHX8wTJ0bjDXyONZolZHjl0g1pQ3tPccZYHRj_FFS_5jpO>==&gt;Land Anywhere Worldswide With 25,000 Airport!==&gt;Real World Instrument Behaviour==&gt;Changable, Unpredictable Real-Time Weather Fasten Your Seatbelts &amp; Prepare To Take Flight! <http://www.noflem.date/hkeja/swdecr31drvszty/uMiFCMuWqsqv30RUTjAE6Px2MB44CIYCV-1tGaeRefo/WM6pQxTIkSftU5DtI4wCcP0IycM12PFvPUSfrri_ihbttbluOqtE5Iw2qrONQYsKQHByoiINfeymEqrejohHX8wTJ0bjDXyONZolZHjl0g1pQ3tPccZYHRj_FFS_5jpO> You can be asked to be removed by going here <http://www.noflem.date/jfoqqvn/Opj5_SFF_jRHYZccPt3Qp1g0ljHZloZNOyXDjb0JTw8XHhojerqEmyefNIioyBHQKsYQNOrq2wI5EtqOulbttbhi_irrfSUPvFP21McyI0PcCw4ItD5UtfSkITxQp6MW.ofeReaGt1-VCYIC44BM2xP6EAjTUR03vqsqWuMCFiMu>or write to us below <!--td {border: 1px solid #ccc;}br {mso-data-placement:same-cell;}-->265 S. Schoolhouse St. Boynton Beach, FL 33435ing --------------008794531541259352341780 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit <html> <head> <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"> </head> <body> <center> <table font-size:="" helvetica="" style="box-sizing: inherit; color: rgb(119, 119, 119); font-family: " width="600px"> <tbody style="box-sizing: inherit;"> <tr style="box-sizing: inherit;"> <td align="left" style="box-sizing: inherit;">&nbsp; <div style="box-sizing: inherit; padding: 8px; border-radius: 10px;"> <center style="box-sizing: inherit;"> <div style="box-sizing: inherit; font-size: 19px;"><b style="box-sizing: inherit;"><a href="http://www.noflem.date/hkeja/swdecr31drvszty/uMiFCMuWqsqv30RUTjAE6Px2MB44CIYCV-1tGaeRefo/WM6pQxTIkSftU5DtI4wCcP0IycM12PFvPUSfrri_ihbttbluOqtE5Iw2qrONQYsKQHByoiINfeymEqrejohHX8wTJ0bjDXyONZolZHjl0g1pQ3tPccZYHRj_FFS_5jpO" rel="nofollow" style="box-sizing: inherit; text-decoration-line: none; color: red;" target="_blank">The Game All Flight Fans Have Been Waiting For Is Finally Here...</a><br style="box-sizing: inherit;" /> <a href="http://www.noflem.date/hkeja/swdecr31drvszty/uMiFCMuWqsqv30RUTjAE6Px2MB44CIYCV-1tGaeRefo/WM6pQxTIkSftU5DtI4wCcP0IycM12PFvPUSfrri_ihbttbluOqtE5Iw2qrONQYsKQHByoiINfeymEqrejohHX8wTJ0bjDXyONZolZHjl0g1pQ3tPccZYHRj_FFS_5jpO" rel="nofollow" style="box-sizing: inherit; text-decoration-line: none; color: black;" target="_blank">The World&#39;s Most Realstic Flight Sim</a></b></div> </center> <hr style="box-sizing: inherit; width: 310px; border-width: 3px; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-color: rgb(0, 176, 0);" />&nbsp; <center style="box-sizing: inherit; font-size: 22px; background-color: rgb(254, 253, 53);"><strong style="box-sizing: inherit;"><a href="http://www.noflem.date/hkeja/swdecr31drvszty/uMiFCMuWqsqv30RUTjAE6Px2MB44CIYCV-1tGaeRefo/WM6pQxTIkSftU5DtI4wCcP0IycM12PFvPUSfrri_ihbttbluOqtE5Iw2qrONQYsKQHByoiINfeymEqrejohHX8wTJ0bjDXyONZolZHjl0g1pQ3tPccZYHRj_FFS_5jpO" rel="nofollow" style="box-sizing: inherit; text-decoration-line: none; color: rgb(65, 82, 73);" target="_blank"><span style="box-sizing: inherit; color: rgb(255, 0, 0);">Watch The Amazing Video Demo Below:</span></a></strong></center> &nbsp; <div style="box-sizing: inherit; font-size: 19px;">==&gt;Fly Over 200+ Different Aircraft<br style="box-sizing: inherit;" /> <br style="box-sizing: inherit;" /> ==&gt;Real Controls Based on Real Cockpits!<br style="box-sizing: inherit;" /> &nbsp; <center style="box-sizing: inherit;"><a href="http://www.noflem.date/hkeja/swdecr31drvszty/uMiFCMuWqsqv30RUTjAE6Px2MB44CIYCV-1tGaeRefo/WM6pQxTIkSftU5DtI4wCcP0IycM12PFvPUSfrri_ihbttbluOqtE5Iw2qrONQYsKQHByoiINfeymEqrejohHX8wTJ0bjDXyONZolZHjl0g1pQ3tPccZYHRj_FFS_5jpO" rel="nofollow" style="box-sizing: inherit; text-decoration-line: none; color: rgb(66, 133, 245);" target="_blank"><img alt="vp3flight" src="http://www.noflem.date/plane_flight.jpg" style="box-sizing: inherit;" /></a></center> <br style="box-sizing: inherit;" /> ==&gt;Land Anywhere Worldswide With 25,000 Airport!<br style="box-sizing: inherit;" /> <br style="box-sizing: inherit;" /> ==&gt;Real World Instrument Behaviour<br style="box-sizing: inherit;" /> <br style="box-sizing: inherit;" /> ==&gt;Changable, Unpredictable Real-Time Weather</div> &nbsp; <center style="box-sizing: inherit;"> <div style="box-sizing: inherit; font-size: 19px; background-color: rgb(55, 102, 144); padding: 8px; border-radius: 15px;"><span style="box-sizing: inherit; font-size: 22px;"><b style="box-sizing: inherit;"><a href="http://www.noflem.date/hkeja/swdecr31drvszty/uMiFCMuWqsqv30RUTjAE6Px2MB44CIYCV-1tGaeRefo/WM6pQxTIkSftU5DtI4wCcP0IycM12PFvPUSfrri_ihbttbluOqtE5Iw2qrONQYsKQHByoiINfeymEqrejohHX8wTJ0bjDXyONZolZHjl0g1pQ3tPccZYHRj_FFS_5jpO" rel="nofollow" style="box-sizing: inherit; text-decoration-line: none; color: rgb(255, 255, 255);" target="_blank">Fasten Your Seatbelts &amp; Prepare To Take Flight!</a></b></span></div><br /> <img src="http://www.noflem.date/Mfqs4im7f/uMiFCMuWqsqv30RUTjAE6Px2MB44CIYCV-1tGaeRefo/WM6pQxTIkSftU5DtI4wCcP0IycM12PFvPUSfrri_ihbttbluOqtE5Iw2qrONQYsKQHByoiINfeymEqrejohHX8wTJ0bjDXyONZolZHjl0g1pQ3tPccZYHRj_FFS_5jpO" > </center> <hr style="box-sizing: inherit; width: 600px; border-width: 5px; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-color: rgb(255, 0, 0);" /></div> <p style="text-align: center;"><br style="box-sizing: inherit;" /> <br style="box-sizing: inherit;" /> <br style="box-sizing: inherit;" /> You can be asked to be removed by going <a href="http://www.noflem.date/jfoqqvn/Opj5_SFF_jRHYZccPt3Qp1g0ljHZloZNOyXDjb0JTw8XHhojerqEmyefNIioyBHQKsYQNOrq2wI5EtqOulbttbhi_irrfSUPvFP21McyI0PcCw4ItD5UtfSkITxQp6MW.ofeReaGt1-VCYIC44BM2xP6EAjTUR03vqsqWuMCFiMu">here </a>or write to us below</p> <center style="box-sizing: inherit;"> <style type="text/css"><!--td {border: 1px solid #ccc;}br {mso-data-placement:same-cell;}--> </style> <span 28="" 361="" 7648="" 8619="" 872="" alton="" arnold="" ave.="" boynton="" chapel="" colonial="" ct="" data-sheets-userformat="{" data-sheets-value="{" fl="" ga="" oh="" pa="" road="" s.="" schoolhouse="" south="" st.="" style="font-size: 11pt; font-family: Calibri, Arial;" textspin:265="" va="" w.="" wall="">265 S. Schoolhouse St. Boynton Beach, FL 33435</span><span style="color: rgb(255, 255, 255); font-size: 4px;">ing</span></center> </td> </tr> </tbody> </table> </center> </body> </html> --------------008794531541259352341780-- `; // Reset `lastIndex` if this regex is defined globally // regex.lastIndex = 0; let m; if ((m = regex.exec(str)) !== null) { // 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