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

/
/
g

Test String

Code Generator

Generated Code

const regex = /(<script[\s\S]*?src[\s\S]*?\=[\s\S]+?\"[/a-zA-Z0-9._-]*\.hyperesources[/a-zA-Z0-9._-]*\.min.js\"[\s\S\]*?>[\s\S]*?<\/script>)/g; // Alternative syntax using RegExp constructor // const regex = new RegExp('(<script[\\s\\S]*?src[\\s\\S]*?\\=[\\s\\S]+?\\"[\/a-zA-Z0-9._-]*\\.hyperesources[\/a-zA-Z0-9._-]*\\.min.js\\"[\\s\\S\\]*?>[\\s\\S]*?<\\\/script>)', 'g') const str = `<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="X-UA-Compatible" content="chrome=1,IE=edge" /> <title>Default</title> <style> html { height:100%; } body { background-color:#FFFFFF; margin:0; height:100%; } </style> <!-- copy these lines to your document head: --> <meta name="viewport" content="user-scalable=no, initial-scale=1.0, width=375" /> <meta name="apple-mobile-web-app-capable" content="yes" /> <script src = "Default.hyperesources/HYPE-584.thin.min.js"></script> <!-- end copy --> </head> <body> <!-- copy these lines to your document: --> <div id="default_hype_container" style="margin:auto;position:relative;width:375px;height:667px;overflow:hidden;"> </div> <!-- end copy --> <script type="text/javascript" charset="utf-8"> // HYPE.documents["Default"] (function(){(function k(){function l(a,b,d){var c=!1;null==window[a]&&(null==window[b]?(window[b]=[],window[b].push(k),a=document.getElementsByTagName("head")[0],b=document.createElement("script"),c=h,false==!0&&(c=""),b.type="text/javascript",b.src=c+"/"+d,a.appendChild(b)):window[b].push(k),c=!0);return c}var h="Default.hyperesources",c="Default",e="default_hype_container";if(false==!1)try{for(var f=document.getElementsByTagName("script"), a=0;a<f.length;a++){var b=f[a].src,d=null!=b?b.indexOf("/default_hype_generated_script.js"):-1;if(-1!=d){h=b.substr(0,d);break}}}catch(n){}if(false==!1&&(a=navigator.userAgent.match(/MSIE (\\d+\\.\\d+)/),a=parseFloat(a&&a[1])||null,a=l("HYPE_584","HYPE_dtl_584",!0==(null!=a&&10>a||false==!0)?"HYPE-584.full.min.js":"HYPE-584.thin.min.js"),false==!0&&(a=a||l("HYPE_w_584","HYPE_wdtl_584","HYPE-584.waypoints.min.js")),a))return;f=window.HYPE.documents; if(null!=f[c]){b=1;a=c;do c=""+a+"-"+b++;while(null!=f[c]);d=document.getElementsByTagName("div");b=!1;for(a=0;a<d.length;a++)if(d[a].id==e&&null==d[a].getAttribute("HYP_dn")){var b=1,g=e;do e=""+g+"-"+b++;while(null!=document.getElementById(e));d[a].id=e;b=!0;break}if(!1==b)return}b=[];b=[];d={};g={};for(a=0;a<b.length;a++)try{g[b[a].identifier]=b[a].name,d[b[a].name]=eval("(function(){return "+b[a].source+"})();")}catch(m){window.console&&window.console.log(m),d[b[a].name]= function(){}}a=new HYPE_584(c,e,{"3":{p:1,n:"time%20change_2x.png",g:"16",o:true,t:"@2x"},"1":{p:1,n:"tag_layout_2x.jpg",g:"10",o:true,t:"@2x"},"2":{p:1,n:"time%20change.png",g:"16",o:true,t:"@1x"},"0":{p:1,n:"tag_layout.jpg",g:"10",o:true,t:"@1x"}},h,[],d,[{n:"Untitled Scene",o:"1",X:[0]}],[{o:"3",p:"600px",cA:false,Y:375,Z:667,L:[],c:"#FFFFFF",bY:1,d:375,U:{"47":{V:{"Main Timeline":"60"},W:"60",n:"inputsymbol"}},T:{"60":{c:"47",z:0,i:"60",n:"Main Timeline",a:[],f:30,b:[]},kTimelineDefaultIdentifier:{i:"kTimelineDefaultIdentifier",n:"Main Timeline",z:1,b:[{D:0,H:true,E:true,z:false,F:0,G:0,C:0.21,b:"60"}],a:[{f:"c",y:0,z:0.1,i:"c",e:48,s:24,o:"58"},{f:"c",y:0,z:0.1,i:"d",e:48,s:24,o:"58"},{f:"c",y:0,z:0.1,i:"e",e:0.76705893987341767,s:0,o:"58"},{f:"c",y:0,z:0.1,i:"b",e:16,s:29,o:"58"},{f:"c",y:0,z:0.1,i:"a",e:325,s:340,o:"58"},{f:"c",y:0.1,z:0.04,i:"a",e:337,s:325,o:"58"},{f:"c",y:0.1,z:0.04,i:"b",e:26,s:16,o:"58"},{f:"c",y:0.1,z:0.04,i:"c",e:28,s:48,o:"58"},{f:"c",y:0.1,z:0.04,i:"d",e:28,s:48,o:"58"},{f:"c",y:0.1,z:0.04,i:"e",e:0,s:0.76705893987341767,o:"58"},{f:"c",y:0.14,z:0.07,i:"e",e:1,s:0,o:"55"},{y:0.14,i:"a",s:337,z:0,o:"58",f:"c"},{y:0.14,i:"b",s:26,z:0,o:"58",f:"c"},{y:0.14,i:"c",s:28,z:0,o:"58",f:"c"},{y:0.14,i:"d",s:28,z:0,o:"58",f:"c"},{y:0.14,i:"e",s:0,z:0,o:"58",f:"c"},{f:"c",y:0.21,z:0.09,i:"b",e:105,s:347,o:"47"},{y:0.21,i:"e",s:1,z:0,o:"55",f:"c"},{y:1,i:"b",s:105,z:0,o:"47",f:"c"}],f:30}},bZ:180,O:["55","53","58","57","51","47","49","56","59","54","48","50","52"],n:"Untitled Layout","_":0,v:{"57":{c:373,d:319,I:"Solid",J:"Solid",K:"Solid",g:"#FFFFFF",L:"Solid",M:1,N:1,A:"#D8DDE4",x:"visible",j:"absolute",B:"#D8DDE4",P:1,k:"div",C:"#D8DDE4",z:5,O:1,D:"#D8DDE4",a:0,b:346},"47":{x:"visible",a:71,cA:false,bX:false,j:"absolute",b:347,c:236,k:"div",bY:1,d:160,z:4,bZ:180,cV:[]},"53":{h:"10",p:"no-repeat",x:"visible",a:0,q:"100% 100%",b:0,j:"absolute",dB:"img",z:2,k:"div",c:375,d:667,r:"inline",cQ:1,cR:1},"58":{c:24,d:24,I:"Solid",e:0,J:"Solid",K:"Solid",g:"#0096FF",L:"None",M:1,N:1,aI:"50%",A:"#D8DDE4",x:"visible",O:1,j:"absolute",aJ:"50%",k:"div",C:"#D8DDE4",z:9,B:"#D8DDE4",D:"#D8DDE4",aK:"50%",P:0,a:340,aL:"50%",b:29},"48":{c:198,d:38,I:"Solid",J:"Solid",K:"Solid",Y:41,g:"#E8EBED",L:"Solid",M:1,w:"9:00",aI:10,A:"#D8DDE4",N:1,O:1,x:"visible",aJ:10,j:"absolute",C:"#D8DDE4",z:12,k:"div",D:"#D8DDE4",aK:10,B:"#D8DDE4",bF:"47",P:1,a:17,F:"center",aL:10,b:60},"54":{G:"#595959",aU:8,c:325,aV:8,d:136,r:"inline",s:"'Helvetica Neue',Arial,Helvetica,Sans-Serif",t:16,Y:24,Z:"break-word",w:"<span style=\\"font-style: normal;\\" data-sheets-value=\\"{&quot;1&quot;:2,&quot;2&quot;:&quot;Forget to log something from earlier in the day, or even yesterday? Look for the clock icon on the top right for food and drink, details and context, and thinking and feeling logs. If you want to attribute the log to the previous day, just tap the 'for yesterday' option.&quot;}\\" data-sheets-userformat=\\"{&quot;2&quot;:4865,&quot;3&quot;:[null,0],&quot;11&quot;:4,&quot;12&quot;:0,&quot;15&quot;:&quot;Helvetica Neue&quot;}\\">Forget to log something from earlier in the day, or even yesterday? Look for the clock icon on the top right for food and drink, details and context, and thinking and feeling logs. If you want to attribute the log to the previous day, just tap the 'for yesterday' option.</span><br>",j:"absolute",x:"visible",k:"div",y:"preserve",z:8,aS:8,aT:8,a:18,b:409},"59":{G:"#000000",aU:8,c:264,d:18,aV:8,r:"inline",s:"'Helvetica Neue',Arial,Helvetica,Sans-Serif",t:21,Z:"break-word",v:"normal",w:"Change the time of your log",A:"#FFFFFF",x:"visible",j:"absolute",B:"#FFFFFF",y:"preserve",k:"div",C:"#FFFFFF",z:7,aS:8,D:"#FFFFFF",aT:8,a:63,b:369},"50":{aV:8,w:"Cancel<br>",x:"visible",a:20,Z:"break-word",b:120,y:"preserve",j:"absolute",z:14,yy:"nowrap",s:"Helvetica,Arial,Sans-Serif",aT:8,k:"div",bF:"47",aS:8,t:16,aU:8,G:"#0096FF",r:"inline"},"55":{c:386,d:666,I:"Solid",e:0,J:"Solid",K:"Solid",g:"rgba(0, 0, 0, 0.341)",L:"None",aP:"default",M:1,N:1,A:"#D8DDE4",x:"visible",aA:{a:[{i:0,b:"kTimelineDefaultIdentifier",p:9,symbolOid:"2"},{b:"kTimelineDefaultIdentifier",p:3,z:false,symbolOid:"2"}]},O:1,j:"absolute",k:"div",dB:"button",z:3,C:"#D8DDE4",D:"#D8DDE4",B:"#D8DDE4",P:0,a:-5,b:0},"49":{aV:8,w:"Change Time",x:"visible",a:61,Z:"break-word",b:14,y:"preserve",j:"absolute",z:11,yy:"nowrap",s:"Helvetica,Arial,Sans-Serif",aT:8,k:"div",bF:"47",aS:8,t:16,aU:8,G:"#000000",r:"inline"},"51":{c:234,d:158,I:"Solid",J:"Solid",K:"Solid",g:"#FFFFFF",L:"Solid",M:1,N:1,aI:10,A:"#929292",x:"visible",j:"absolute",O:1,aJ:10,k:"div",C:"#929292",z:10,B:"#929292",D:"#929292",aK:10,bF:"47",P:1,a:0,aL:10,b:0},"56":{h:"16",p:"no-repeat",x:"visible",a:23,q:"100% 100%",b:369,j:"absolute",dB:"img",z:6,k:"div",c:40,d:40,r:"inline"},"52":{aV:8,w:"Save",x:"visible",a:159,Z:"break-word",b:120,y:"preserve",j:"absolute",z:13,yy:"nowrap",s:"Helvetica,Arial,Sans-Serif",aT:8,k:"div",bF:"47",aS:8,t:16,aU:8,G:"#0096FF",r:"inline"}}}],{},g,{},null,false,true,-1,true,true,true,false);f[c]=a.API;document.getElementById(e).setAttribute("HYP_dn", c);a.z_o(this.body)})();})(); </script> <!-- text content for search engines: --> <div style="display:none" aria-hidden=true> <div>Forget to log something from earlier in the day, or even yesterday? Look for the clock icon on the top right for food and drink, details and context, and thinking and feeling logs. If you want to attribute the log to the previous day, just tap the 'for yesterday' option. </div> <div>Change the time of your log</div> <div>9:00</div> <div>Change Time</div> <div>Cancel </div> <div>Save</div> </div> <!-- end text content: --> </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