Regular Expressions 101

Save & Share

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

/
/
.style

Test String

Code Generator

Generated Code

const regex = /<!--block:(.*?)-->((?:(?:(?!<!--(.*?)-->).)|(?R))*?)<!--endblock-->/sy; // Alternative syntax using RegExp constructor // const regex = new RegExp('<!--block:(.*?)-->((?:(?:(?!<!--(.*?)-->).)|(?R))*?)<!--endblock-->', 'sy') const str = `<!DOCTYPE html><html><head><title>Crew Watch (Responses)</title> <link href='/static/spreadsheets2/client/css/461985016-waffle_k_ltr.css' type='text/css' rel='stylesheet'><style type="text/css"> html { overflow: visible; } #sheets-viewport { overflow: auto; } #sheets-viewport.widget-viewport { overflow: hidden; } .grid-container { overflow: visible; background: white;} .grid-table-container { overflow: visible; } #top-bar { background: url("//ssl.gstatic.com/docs/spreadsheets/publishheader.png") repeat-x bottom; margin: 0; overflow: hidden; } #top-bar { border-bottom: 1px solid #ccc; padding: 6px 6px 0; } #doc-title { padding-bottom: 5px; } #doc-title .name { font-size: 15px; } #sheet-menu { font-size: 13px; margin: 6px 0 0; padding: 0 0 5px; } #sheet-menu li { display: inline; list-style-type: none; margin: 0; padding: 5px 8px; } #sheet-menu li.active { background-color: #fff; font-weight: bold; border: 1px solid #999; } #top-bar #sheet-menu li.active { border-bottom: 0; } #sheet-menu a, #sheet-menu a:visited { color: #07c; } .ritz .waffle .s0{text-align:left;color:#000000;background-color:#ffffff;font-family:arial,sans,sans-serif;font-size:10pt;vertical-align:bottom;white-space:nowrap;direction:ltr;padding:2px 3px 2px 3px;}.ritz .waffle .s1{text-align:right;color:#000000;background-color:#ffffff;font-family:arial,sans,sans-serif;font-size:10pt;vertical-align:bottom;white-space:nowrap;direction:ltr;padding:2px 3px 2px 3px;}</style><script type="text/javascript"> var activeSheetId; function switchToSheet(id) { if (document.getElementById('sheet-menu')) { document.getElementById('sheet-button-' + activeSheetId) .className = ''; document.getElementById('sheet-button-' + id).className = 'active'; } document.getElementById(activeSheetId).style.display = 'none'; document.getElementById(id).style.display = ''; activeSheetId = id; // posObjs() is defined in embeddedObjectJs (see EmbeddedObjectHtmlBuilder.java) posObjs(); return false; } function init() { var optPageSwitcher; function resize() { var optTopBar = document.getElementById('top-bar'); var adjustedHeight = window.innerHeight - (optTopBar ? optTopBar.offsetHeight : 0); var adjustedWidth = window.innerWidth; var sheetsViewport = document.getElementById('sheets-viewport'); sheetsViewport.style.width = (adjustedWidth + 'px'); sheetsViewport.style.height = (adjustedHeight + 'px'); if (optPageSwitcher) { optPageSwitcher.resize(adjustedWidth, adjustedHeight); } } resize(); window.onresize = resize; } </script></head><body onload=init()><div id="top-bar"><div id="doc-title"><span class="name">Crew Watch (Responses) : Form Responses 1</span></div></div><div id="sheets-viewport"><div id="1416730418" style="display:none;position:relative;" dir="ltr"><div class="ritz grid-container" dir="ltr"><table class="waffle" cellspacing="0" cellpadding="0"><thead><tr><th class="row-header freezebar-vertical-handle header-shim row-header-shim"></th><th id="1416730418C0" style="width:150px" class="header-shim"></th><th id="1416730418C1" style="width:150px" class="header-shim"></th><th id="1416730418C2" style="width:150px" class="header-shim"></th><th id="1416730418C3" style="width:150px" class="header-shim"></th><th id="1416730418C4" style="width:150px" class="header-shim"></th><th id="1416730418C5" style="width:150px" class="header-shim"></th><th id="1416730418C6" style="width:150px" class="header-shim"></th><th id="1416730418C7" style="width:150px" class="header-shim"></th><th id="1416730418C8" style="width:150px" class="header-shim"></th></tr></thead><tbody><tr style='height:21px;'><th id="1416730418R0" style="height: 21px;" class="row-headers-background row-header-shim"><div class="row-header-wrapper" style="line-height: 21px;">1</div></th><td class="s0">Timestamp</td><td class="s0">First Name</td><td class="s0">Middle Name</td><td class="s0">Last Name</td><td class="s0">Date of Birth</td><td class="s0">Street Address</td><td class="s0">City</td><td class="s0">State</td><td class="s0">Zip Code</td></tr><tr><th style="height:4px" class="freezebar-cell freezebar-horizontal-handle row-header-shim"></th><td class="freezebar-cell"></td><td class="freezebar-cell"></td><td class="freezebar-cell"></td><td class="freezebar-cell"></td><td class="freezebar-cell"></td><td class="freezebar-cell"></td><td class="freezebar-cell"></td><td class="freezebar-cell"></td><td class="freezebar-cell"></td></tr><tr style='height:21px;'><th id="1416730418R1" style="height: 21px;" class="row-headers-background row-header-shim"><div class="row-header-wrapper" style="line-height: 21px;">2</div></th><td class="s1" dir="ltr">3/26/2014 21:33:20</td><td class="s0" dir="ltr">John</td><td class="s0" dir="ltr">Collier</td><td class="s0" dir="ltr">Armstrong</td><td></td><td></td><td></td><td></td><td></td></tr><tr style='height:21px;'><th id="1416730418R2" style="height: 21px;" class="row-headers-background row-header-shim"><div class="row-header-wrapper" style="line-height: 21px;">3</div></th><td class="s1" dir="ltr">8/21/2014 0:56:02</td><td class="s0" dir="ltr">john</td><td class="s0" dir="ltr">collier</td><td class="s0" dir="ltr">armstrong</td><td class="s1" dir="ltr">1/10/1984</td><td class="s0" dir="ltr">4720 SW 21st St.</td><td class="s0" dir="ltr">Topeka</td><td></td><td class="s1" dir="ltr">66604</td></tr><tr style='height:21px;'><th id="1416730418R3" style="height: 21px;" class="row-headers-background row-header-shim"><div class="row-header-wrapper" style="line-height: 21px;">4</div></th><td class="s1" dir="ltr">9/11/2014 0:56:28</td><td class="s0" dir="ltr">Conner</td><td class="s0" dir="ltr">Goss</td><td class="s0" dir="ltr">Griffin</td><td class="s1" dir="ltr">8/31/1992</td><td></td><td class="s0" dir="ltr">Topeka</td><td></td><td></td></tr></tbody></table></div></div></div> <script type='text/javascript'> function posObj(sheet, id, row, col, x, y) { var r = document.getElementById(sheet+'R'+row); var c = document.getElementById(sheet+'C'+col); if (r && c) { var s = document.getElementById(id).style; var t = y; while (r) { t += r.offsetTop; r = r.offsetParent; } var l = x; while (c) { l += c.offsetLeft; c = c.offsetParent; } s.left = l + 'px'; s.top = t + 'px'; s.display = 'block'; s.border = '1px solid #000000'; } }; function posObjs() { }; posObjs();</script> <script type="text/javascript">activeSheetId = '1416730418'; switchToSheet('1416730418');</script></body></html>`; // 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