Regular Expressions 101

Save & Share

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

/
/
gs

Test String

Code Generator

Generated Code

const regex = /\{{(.*?)\}}/gs; // Alternative syntax using RegExp constructor // const regex = new RegExp('\\{{(.*?)\\}}', 'gs') const str = `kjasgdfkjhg asjgdjasgd kjasghd kjasdgd . () {} {{ sdwfhklsd<dfdfdf///df/ "" ''sdsd >fklsdfljhksdfkjh. /asdfsdf/sfdsdfs()df\\sdfsdfsdf][][][{][[] }} {{ try{ var s_5ka={gen204:"xjs2es",clearcut:32};s_fk("csies");s_ka("window.google.timers.load.t")&&google.tick("load",s_5ka); s__i("csies");s_fl(); }catch(e){_DumpException(e)} /* _Module_:emb */ try{ s_fk("emb"); s__i("emb");s_fl(); }catch(e){_DumpException(e)} /* _Module_:emc */ try{ s_fk("emc"); s__i("emc");s_fl(); }catch(e){_DumpException(e)} /* _Module_:emd */ try{ s_fk("emd"); s__i("emd");s_fl(); }catch(e){_DumpException(e)} /* _Module_:eme */ try{ s_fk("eme"); s__i("eme");s_fl(); }catch(e){_DumpException(e)} /* _Module_:sy4o */ try{ var s_2i,s_dka,s_3i,s_fka,s_hla=function(a,b){return a.left<=b.left+b.width&&b.left<=a.left+a.width&&a.top<=b.top+b.height&&b.top<=a.top+a.height};s_fk("sy4o");var s_4i=s_d,s_B=s_d,s_5i=s_qd(0),s_6i=s_qd(0),s_7i=s_qd(0),s_gka=function(a,b){window.scrollBy(a,b)},s_8i=function(a,b){window.scrollTo(a,b)},s_9i=s_rd,s_\$i=s_rd,s_hka=s_d,s_ika=s_d,s_jka=s_d,s_X\$b=s_rd,s_aj=function(){if(document.body){var a=s_6d(document.body).top;s_aj=s_qd(a);return a}return 0},s_E\$a=s_lb.match(/ GSA\\/([.\\d]+)/),s_F\$a=s_E\$a?s_E\$a[1]:"";s_dka=(s_2i=!!s_E\$a||!!window.agsa_ext)&&0<=s_Ia(s_F\$a,"4");s_3i=s_2i&&0<=s_Ia(s_F\$a,"5.2"); s_fka=s_2i&&0<=s_Ia(s_F\$a,"4.3")&&!(0<=s_Ia(s_F\$a,"4.5")); s__i("sy4o");s_fl(); }catch(e){_DumpException(e)} /* _Module_:sy4z */ try{ s_fk("sy4z");var s_8ka={},s_\$ka=function(a,b,c){var d=c?1:0;if(!s_ka(0!=d?"velour.loadJsInterfaceWithFlags":"velour.loadJsInterface"))return s_Qe(Error("G"));a in s_8ka||(s_8ka[a]={});c=s_8ka[a];if(c[b])return c[b];var e=s_Se(),f=0!=d?window.velour.loadJsInterfaceWithFlags(a,b,d):window.velour.loadJsInterface(a,b);d="google.velourCb."+a+"."+b;s_ta(d,{onSuccess:function(){e.resolve(f.getResult())},onFailure:function(){e.reject(a+"."+b+" failed to load: "+f.getError().getMessage())}});f.setCallback(d);return c[b]= e.Mc},s_8la=function(a,b,c,d){for(var e=[a,b,!1],f=2;f<arguments.length;f++)e.push(arguments[f]);return s_ela.apply(null,e)},s_ela=function(a,b,c,d,e){for(var f=s_\$ka(a,b,c),g=[],k=4;k<arguments.length;k++)g.push(arguments[k]);return f.then(function(a){return a[d]?a[d].apply(a,g):s_Qe(Error("Za\`"+d))})}; s__i("sy4z");s_fl(); }catch(e){_DumpException(e)} /* _Module_:sy64 */ try{ s_fk("sy64");var s_xdb,s_ydb=!1,s_Adb=function(){var a=s_D\$a;s_hc(window,"beforeunload",function(){s_ydb||s_xdb.set("isn",a)})};if(s_2i){s_xdb=s_ng("s","isn");var s_D\$a;var s_G\$a,s_H\$a,s_Kib=(s_3j().get("isn")||"").split(":");s_H\$a=s_Kib[0];s_G\$a=s_Kib[1];if(s_H\$a){var s_ajb={};s_D\$a=(s_ajb[s_G\$a]=s_H\$a,s_ajb)}else s_D\$a=null;s_D\$a&&s_Adb()}; s__i("sy64");s_fl(); }catch(e){_DumpException(e)} /* _Module_:aa */ try{ s_fk("aa"); s__i("aa");s_fl(); }catch(e){_DumpException(e)} /* _Module_:abd */ try{ s_fk("abd");var s_iz=function(a){for(var b="",c=21,d=0;d<a.length;d++)3!=d%4&&(b+=String.fromCharCode(a[d]^c),c++);return b},s_S5a=s_iz([97,119,115,111,107]),s_T5a=s_iz([97,119,115,111,107,123]),s_U5a=s_iz([118,115,121,107,108,124,104,119,68,127,114,105,114]),s_V5a=s_iz([101,126,118,102,118,125,118,109,126]),s_W5a=s_iz([116,116,115,108]),s_X5a=s_iz([113,115,99,107]),s_Y5a=s_iz([113,115,117,107]),s_Z5a=s_iz([58,127,122,103,121,126,127,98,104,51,109,124,118,123,15,76,81,90,13,95,67,76,64,118]),s__5a=function(a){var b= 0,c;for(c in a)if(a[c].e)if(a[c].b)b++;else return!1;return 0<b},s_05a=function(a){a=a||{};var b={};b[s_X5a]={e:!!a[s_X5a],b:!s_7ma(s_S5a)};b[s_Y5a]={e:!!a[s_Y5a],b:!s_7ma(s_T5a)};return b},s_15a=function(a){var b=[],c;for(c in a)a[c].e&&b.push(c+":"+(a[c].b?"1":"0"));return b.join(",")},s_25a=function(a,b){a=String(a);b&&(a+=","+b);google.log(s_V5a,a)},s_35a=function(a,b,c){c=null!=c?c:2;if(1>c)s_25a(7,b);else{var d=new Image;d.onerror=s_f(s_35a,a,b,c-1);d.src=a}},s_r_b={}; s_hf("abd",(s_r_b.init=function(a){a=a||{};if(a[s_W5a]&&s_7ma(s_U5a)){a=s_05a(a);var b=s_15a(a);s__5a(a)?s_25a(1,"0,"+b):s_25a(0,b);s_H.qc(function(){s_35a(s_Z5a,"aa")})}},s_r_b)); s__i("abd");s_fl(); }catch(e){_DumpException(e)} /* _Module_:aspn */ try{ s_fk("aspn");var s_0pb=function(a){var b=a.getAttribute("data-url");window.open(b,"_blank","menubar=no,left="+((window.screenLeft||window.screenX||0)+Math.max(0,((window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth||0)-445)/2))+",top="+((window.screenTop||window.screenY||0)+Math.max(0,((window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight||0)-665)/2))+",width=445,height=665");(a=a.getAttribute("data-ved"))&&google.log("","&ved="+a)},s_1xa={}; s_hf("aspn",(s_1xa.init=function(){s_Oh("aspn",{ota:s_0pb},!0)},s_1xa)); s__i("aspn");s_fl(); }catch(e){_DumpException(e)} /* _Module_:sy3g */ try{ }} `; // 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