Regular Expressions 101

Save & Share

  • Regex Version: ver. 2
  • 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

/
/
gms

Test String

Substitution

Processing...

Code Generator

Generated Code

const regex = /<p( style="[^>]*?")?>(.*?)<\/p>/gms; // Alternative syntax using RegExp constructor // const regex = new RegExp('<p( style="[^>]*?")?>(.*?)<\\\/p>', 'gms') const str = `<div style="background-color: #ecedef; padding: 1em 0px;"> <table border="0" cellpadding="0" cellspacing="0" align="center" style="max-width:600px; margin: 0 auto;"> <tbody> <tr> <td> <div class="elementEditable secEdit" style="background-color:#fff;"> <table class="tableMail" border="0" cellpadding="0" cellspacing="0" style="width:100%;max-width:600px;margin: 0 auto;"> <tbody> <tr> <td style="width: 25%;">&nbsp;</td> <td class="cellLogoCustom" style="padding:30px;text-align:center;position:relative;"> <img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSgBBwcHCggKEwoKEygaFhooKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKP/AABEIAAoAGQMBEQACEQEDEQH/xAGiAAABBQEBAQEBAQAAAAAAAAAAAQIDBAUGBwgJCgsQAAIBAwMCBAMFBQQEAAABfQECAwAEEQUSITFBBhNRYQcicRQygZGhCCNCscEVUtHwJDNicoIJChYXGBkaJSYnKCkqNDU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6g4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2drh4uPk5ebn6Onq8fLz9PX29/j5+gEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoLEQACAQIEBAMEBwUEBAABAncAAQIDEQQFITEGEkFRB2FxEyIygQgUQpGhscEJIzNS8BVictEKFiQ04SXxFxgZGiYnKCkqNTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqCg4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2dri4+Tl5ufo6ery8/T19vf4+fr/2gAMAwEAAhEDEQA/APqmgAoAKAPzW+LH/JU/GX/Yavf/AEe9AHVf8NB/E/8A6Gb/AMkLX/43QAf8NB/E/wD6Gb/yQtf/AI3QAf8ADQfxP/6Gb/yQtf8A43QB5rq2oXWr6realqEvnXt5M9xPJtC75HYsxwAAMkngDFAH/9k=" style=" max-width: 250px; "> </td> <td style="width: 25%;">&nbsp;</td> </tr> </tbody> </table> </div> <div class="elementEditable secEdit" style="color: rgb(255, 255, 255); background-color: rgb(0, 115, 182); font-family: Arial; text-align: center; font-weight: normal; font-style: normal; font-size: 15px;"> <table class="tableMail" border="0" cellpadding="0" cellspacing="0" style="width:100%; max-width:600px; margin: 0 auto;"> <tbody> <tr> <td style="padding:30px;text-align:center;"> <p style="font-weight: lighter; text-align: center; font-family: Arial; font-size: 15px; background-color: rgb(0, 115, 182); color: rgb(255, 255, 255);"> Ordine completato!</p> </td> </tr> </tbody> </table> </div> <div class="elementEditable secEdit" style="background: rgb(255, 255, 255); color: rgb(51, 51, 51); font-family: Arial; font-weight: lighter; font-size: 14px;"> <table class="tableMail" border="0" cellpadding="0" cellspacing="0" style="width:100%; max-width:600px; margin: 0 auto;"> <tbody> <tr> <td style="padding:40px 30px 40px 30px;"> <p style="font-weight: lighter; color: rgb(51, 51, 51); font-family: Arial; font-size: 14px;"> Il tuo ordine (#%order_id%) è stato ricevuto ed è in elaborazione.<br> Il dettaglio dell'ordine è mostrato di seguito perché possa consultarlo: </p> </td> </tr> </tbody> </table> </div> <div class="elementEditable std tabEdit" style="font-family: Arial; background-color: rgb(255, 255, 255); font-size: 13px;"> <table class="tableMail" border="0" cellpadding="0" cellspacing="0" style="width:100%;max-width:600px;margin: 0 auto;"> <tbody> <tr style=""> <td style="padding: 30px; border-color: rgb(236, 237, 239); color: rgb(51, 51, 51);"> <table cellspacing="0" cellpadding="6" style="width:100%;border: 1px solid #eee;"> <thead> <tr> <th scope="col" style="text-align: left; border: 1px solid rgb(236, 237, 239); padding: 12px; color: rgb(51, 51, 51);"> <p>Prodotto</p> </th> <th scope="col" style="text-align: left; border: 1px solid rgb(236, 237, 239); padding: 12px; color: rgb(51, 51, 51);"> <p>Quantità</p> </th> <th scope="col" style="text-align: left; border: 1px solid rgb(236, 237, 239); padding: 12px; color: rgb(51, 51, 51);"> <p>Prezzo</p> </th> </tr> </thead> <tbody> <!-- product list --> <tr> <td style="text-align: left; vertical-align: middle; border: 1px solid rgb(236, 237, 239); word-wrap: break-word; padding: 12px; color: rgb(51, 51, 51);">Prodotto 1</td> <td style="text-align: left; vertical-align: middle; border: 1px solid rgb(236, 237, 239); padding: 12px; color: rgb(51, 51, 51);">1</td> <td style="text-align: left; vertical-align: middle; border: 1px solid rgb(236, 237, 239); padding: 12px; color: rgb(51, 51, 51);">EUR 12.50</td> </tr> <!-- product list --> </tbody> <tfoot> <tr> <th scope="row" colspan="2" style="text-align: left; border: 1px solid rgb(236, 237, 239); padding: 12px; color: rgb(51, 51, 51);"> <p>Subtotale:</p> </th> <td style="text-align: left; border: 1px solid rgb(236, 237, 239); padding: 12px; color: rgb(51, 51, 51);"><span>%curr% %order_subtotal%</span></td> </tr> <tr> <th scope="row" colspan="2" style="text-align: left; border: 1px solid rgb(236, 237, 239); padding: 12px; color: rgb(51, 51, 51);"> <p>Spedizione:</p> </th> <td style="text-align: left; border: 1px solid rgb(236, 237, 239); padding: 12px; color: rgb(51, 51, 51);"> <span>%curr% %order_shipprice%</span> </td> </tr> <tr> <th scope="row" colspan="2" style="text-align: left; border: 1px solid rgb(236, 237, 239); padding: 12px; color: rgb(51, 51, 51);"> <p>Totale:</p> </th> <td style="text-align: left; border: 1px solid rgb(236, 237, 239); padding: 12px; color: rgb(51, 51, 51);"> <span>%curr% %order_total%</span> </td> </tr> </tfoot> </table> </td> </tr> </tbody> </table> </div> <div class="elementEditable headEdit"> <table class="tableMail" border="0" cellpadding="0" cellspacing="0" style="width:100%; max-width:600px; margin: 0 auto; background: #ccc;"> <tbody> <tr style="background:#fff;"> <th style="padding:10px 30px 0px 30px; color: #555; font-weight: bolder;text-align:left;"> <p>Note:</p> </th> </tr> <tr style="background:#fff;"> <td style="padding:16px 30px 60px 30px; color: #666; font-weight: lighter; lin-height:1.3;text-align:left;"> %order_note% </td> </tr> </tbody> </table> </div> <div class="elementEditable headEdit" style="background-color: rgb(255, 255, 255); font-size: 13px;"> <table class="tableMail" border="0" cellpadding="0" cellspacing="0" style="width:100%;max-width:600px;margin: 0 auto;"> <tbody> <tr style=""> <th style="padding: 10px 30px 0px; color: rgb(51, 51, 51); font-weight: bolder;"> <p>Dettaglio:</p> </th> </tr> <tr style=""> <td style="padding: 16px 30px 60px; color: rgb(51, 51, 51); font-weight: lighter; line-height: 1.6;"> %buyer_name% <br> Email: %buyer_email% <br> Tel: %buyer_phone% </td> </tr> </tbody> </table> </div> <div class="elementEditable std headEdit" style="font-family: Arial; font-size: 13px; background-color: rgb(255, 255, 255);"> <table class="tableMail" border="0" cellpadding="0" cellspacing="0" style="width:100%;max-width:600px;margin: 0 auto;"> <tbody> <tr> <td style="color: rgb(51, 51, 51);"> <table class="tableMail" align="left" border="0" cellpadding="0" cellspacing="0" style="max-width:300px;margin: 0 auto;"> <tbody> <tr style=""> <th style="padding: 10px 30px 0px; color: rgb(51, 51, 51); font-weight: bolder;text-align:left;"> <p>Indirizzo fatturazione:</p> </th> </tr> <tr style=""> <td style="padding: 16px 30px 80px; color: rgb(51, 51, 51); font-weight: lighter; line-height: 1.6;"> %invoice_name% <br> %invoice_fiscal% <br> %invoice_address% - %invoice_zip% <br>%invoice_city% (%invoice_state%) <br>%invoice_country% <br> Email: %invoice_email% <br> Tel: %invoice_phone% </td> </tr> </tbody> </table> <table class="tableMail" align="right" border="0" cellpadding="0" cellspacing="0" style="max-width:300px;margin: 0 auto;"> <tbody> <tr style=""> <th style="padding: 10px 30px 0px; color: rgb(51, 51, 51); font-weight: bolder;text-align:left;"> <p>Indirizzo spedizione:</p> </th> </tr> <tr style=""> <td style="padding: 16px 30px 80px; font-weight: lighter; line-height: 1.6; color: rgb(51, 51, 51);"> %shipping_name% <br> %shipping_fiscal% <br> %shipping_address% - %shipping_zip% <br>%shipping_city% (%shipping_state%) <br>%shipping_country% <br> Email: %shipping_email% </td> </tr> </tbody> </table> </td> </tr> </tbody> </table> </div> <div class="elementEditable secEdit" style="background-color: rgb(0, 115, 182); font-size: 12px; color: rgb(255, 255, 255); font-family: Arial; text-align: center; font-weight: lighter; font-style: italic;"> <table class="tableMail" border="0" cellpadding="0" cellspacing="0" style="width:100%;max-width:600px;margin: 0 auto;"> <tbody> <tr style=""> <td style="padding:20px 30px;text-align:center;"> <p style="font-weight: lighter; font-family: Arial; text-align: center; font-style: italic;">%shop_name%</p> </td> </tr> </tbody> </table> </div> </td> </tr> </tbody> </table> </div>`; const subst = `<div class="myclass"$1>$2</div>`; // The substituted value will be contained in the result variable const result = str.replace(regex, subst); console.log('Substitution result: ', result);

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