{"id":1597,"date":"2025-01-29T22:00:00","date_gmt":"2025-01-29T21:00:00","guid":{"rendered":"https:\/\/demo.sidekick.be\/itenium\/regex-in-javascript\/"},"modified":"2025-11-28T13:31:45","modified_gmt":"2025-11-28T12:31:45","slug":"regex-in-javascript","status":"publish","type":"post","link":"https:\/\/demo.sidekick.be\/itenium\/blog\/javascript\/regex-in-javascript\/","title":{"rendered":"JavaScript RegExp Tutorial"},"content":{"rendered":"<h1 id=\"common-usage\">Common Usage<\/h1>\n<p>Define yourself a regex:<\/p>\n<pre><code class=\"language-javascript\">\/\/ Preferred way\nconst expressionLiteral = \/w+\/;\n\n\/\/ Only use this for dynamic patterns\nconst ctor = new RegExp('\\w+');\n<\/code><\/pre>\n<h2 id=\"regexpprototypetest\">RegExp.prototype.test<\/h2>\n<p style=\"float: right\"><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/RegExp\/test\">RegExp.prototype.test<\/a><\/p>\n<p>Returns <code>true<\/code> or <code>false<\/code>.<\/p>\n<pre><code class=\"language-javascript\">const didMatch = \/a\/.test('abc');\n<\/code><\/pre>\n<h2 id=\"stringprototypereplace\">String.prototype.replace<\/h2>\n<p style=\"float: right\"><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/String\/replace\">String.prototype.replace<\/a><\/p>\n<p>Without the <code>g<\/code> flag, only the first match is replaced. (which makes no difference in the example:)<br \/> ECMAScript2021 added <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/String\/replaceAll\"><code>replaceAll<\/code><\/a>: you can now replace all occurrences without using a regex.<\/p>\n<pre><code class=\"language-javascript\">'too  many  spaces'.replace(\/  \/g, ' ');\n'too  many  spaces'.replaceAll('  ', ' ');\n<\/code><\/pre>\n<table class=\"table-code\">\n<thead>\n<tr>\n<th>Replacement<\/th>\n<th>Description<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>$$<\/code><\/td>\n<td>A literal $<\/td>\n<\/tr>\n<tr>\n<td><code>$`<\/code><\/td>\n<td>Portion before the match<\/td>\n<\/tr>\n<tr>\n<td><code>$'<\/code><\/td>\n<td>Portion after the match<\/td>\n<\/tr>\n<tr>\n<td><code>$&amp;<\/code><\/td>\n<td>The whole matched string<\/td>\n<\/tr>\n<tr>\n<td><code>$n<\/code><\/td>\n<td>With <code>n &lt; 100<\/code>: the nth captured group (!! 1 indexed !!)<\/td>\n<\/tr>\n<tr>\n<td><code>$&lt;Name&gt;<\/code><\/td>\n<td>Named capturing group<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2 id=\"stringprototypematch\">String.prototype.match<\/h2>\n<p><strong>match() with the <code>g<\/code> flag<\/strong>:<\/p>\n<p style=\"float: right\"><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/String\/match\">String.prototype.match<\/a><\/p>\n<p>Returns <code>null<\/code> or all matches as a <code>string[]<\/code>. There is no captured group info.<\/p>\n<pre><code class=\"language-javascript\">const match = 'a_ab_a'.match(\/a(b?)\/g);\nexpect(match).toEqual(['a', 'ab', 'a']);\n<\/code><\/pre>\n<p><strong>match() without the <code>g<\/code> flag<\/strong>:<br \/> Returns <code>null<\/code> or the first match and its capturing groups.<br \/> The result is an array with additional fields (groups, index and input). <code>exec<\/code><\/p>\n<p><small>(Hence the weird toEqual array syntax in the code below\u2026)<\/small><\/p>\n<pre><code class=\"language-javascript\">const match = '0abaa'.match(\/a(?&lt;theB&gt;b?)\/);\nexpect(match).toEqual([\n    0: 'ab', \/\/ Entire matched string\n    1: 'b',  \/\/ First captured group\n    groups: {theB: 'b'}, \/\/ Results of named groups (ES2018)\n    index: 1,\n    input: '0abaa'\n]);\n\n\/\/ Without the g flag, match behaves exactly like exec:\nconst exec = \/a(?&lt;theB&gt;b?)\/.exec('0abaa');\nexpect(exec).toEqual(match);\n<\/code><\/pre>\n<h2 id=\"regexpprototypeexec\">RegExp.prototype.exec<\/h2>\n<p style=\"float: right\"><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/RegExp\/exec\">RegExp.prototype.exec<\/a><\/p>\n<p>When you need the capturing groups of all matches, it\u2019s <code>exec<\/code> to the rescue.<\/p>\n<pre><code class=\"language-javascript\">const globbing = \/(a)(b2?)\/g;\nconst input = 'ab_ab2';\n\/\/ Indexes     0  3  \n\nglobbing.exec(input);\n== Object.assign(['ab', 'a', 'b'], {index: 0});\n\nglobbing.exec(input);\n== Object.assign(['ab2', 'a', 'b2'], {index: 3});\n\nglobbing.exec(input);\n== null\n<\/code><\/pre>\n<h2 id=\"regexpprototypematchall-es2020\">RegExp.prototype.matchAll <small>(ES2020)<\/small><\/h2>\n<p style=\"float: right\"><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/RegExp\/@@matchAll\">RegExp.prototype.matchAll<\/a><\/p>\n<p>Easier matching and grouping, plus avoiding the <code>while<\/code> loop necessary when using the \u201cold\u201d <code>exec<\/code>.<\/p>\n<pre><code class=\"language-javascript\">const regex = \/(a)(b2?)\/g; \/\/ TypeError when not g(lobal)!\nconst result = 'ab_ab2'.matchAll(regex);\n\nfor (const match of result) {\n  \/\/ First match: ['ab', 'a', 'b', index: 0, input: 'ab_ab2', groups: undefined]\n  \/\/ Second match: ['ab2', 'a', 'b2', index: 3, input: 'ab_ab2', groups: undefined]\n}\n<\/code><\/pre>\n<h1 id=\"flags\">Flags<\/h1>\n<pre><code class=\"language-javascript\">const rl = \/ab+c\/i;\nconst rc = new RegExp('ab+c', 'i');\n<\/code><\/pre>\n<p><strong>Available flags<\/strong>:<\/p>\n<table class=\"table-code\">\n<thead>\n<tr>\n<th>Flag<\/th>\n<th>Property<\/th>\n<th>Remarks<\/th>\n<th>StackOverflow<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>i<\/code><\/td>\n<td><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/RegExp\/ignoreCase\">.ignoreCase<\/a><\/td>\n<td>Case insensitive<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><code>g<\/code><\/td>\n<td><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/RegExp\/global\">.global<\/a><\/td>\n<td>Do not stop at first match but find all of them<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><code>m<\/code><\/td>\n<td><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/RegExp\/multiline\">.multiline<\/a><\/td>\n<td><code>^<\/code> and <code>$<\/code> match beginning\/end of each line (otherwise of entire string)<\/td>\n<td><a href=\"https:\/\/stackoverflow.com\/questions\/1979884\/how-to-use-javascript-regex-over-multiple-lines\">StackOverflow<\/a><\/td>\n<\/tr>\n<tr>\n<td><code>s<\/code><\/td>\n<td><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/RegExp\/dotAll\">.dotAll<\/a><\/td>\n<td><code>.<\/code> matches newlines. (ES2018)<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><code>u<\/code><\/td>\n<td><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/RegExp\/unicode\">.unicode<\/a><\/td>\n<td><code>\/^.$\/u.test('\ud83d\ude00')<\/code><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><code>v<\/code><\/td>\n<td><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/RegExp\/unicodeSets\">.unicodeSets<\/a><\/td>\n<td><code>\/^p{RGI_Emoji}$\/v.test('\ud83d\udc68\u200d\ud83d\udc69\u200d\ud83d\udc67\u200d\ud83d\udc66')<\/code> (ES2024)<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><code>y<\/code><\/td>\n<td><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/RegExp\/sticky\">.sticky<\/a><\/td>\n<td>Use <code>.lastIndex<\/code> to match at that specific index <strong>only<\/strong> (overwrites the <code>g<\/code> flag)<\/td>\n<td><a href=\"https:\/\/stackoverflow.com\/questions\/4542304\/what-does-regex-flag-y-do\">StackOverflow<\/a><\/td>\n<\/tr>\n<tr>\n<td><code>d<\/code><\/td>\n<td><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/RegExp\/hasIndices\">.hasIndices<\/a><\/td>\n<td>Adds an <code>indices<\/code> property to the match object that contains the start\/end indices of each capture group (2022)<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/RegExp\/flags\">.flags<\/a><\/td>\n<td>Returns a string with the active flags<\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2 id=\"unicodesets\">UnicodeSets<\/h2>\n<p>The <code>v<\/code> flag doesn\u2019t just bring stuff like <code>p{RGI_Emoji}<\/code> but also extensions to character classes.<br \/> Checkout <a href=\"https:\/\/v8.dev\/features\/regexp-v-flag\">v8.dev<\/a> for a whole bunch of additional examples.<\/p>\n<h3 id=\"subtraction-with---\">Subtraction with <code>--<\/code><\/h3>\n<pre><code class=\"language-js\">\/\/ Only non-ascii numbers\n\/^[p{Decimal_Number}--[0-9]]+$\/v.test('012'); \/\/ false\n\/^[p{Decimal_Number}--[0-9]]+$\/v.test('\u0661\ud835\udfdc\u0969'); \/\/ true\n\n\/\/ Only consonants\n\/^[[a-z]--[aeoiu]]$\/v.test('q'); \/\/ true\n<\/code><\/pre>\n<h3 id=\"intersection-with-\">Intersection with <code>&amp;&amp;<\/code><\/h3>\n<pre><code class=\"language-js\">\/\/ Only Arabic numbers\n\/^[p{Script=Arabic}&amp;&amp;p{Decimal_Number}]+$\/v.test('\u0661\u0662\u0663');\n\n\/\/ Only Greek letters\n\/[p{Script=Greek}&amp;&amp;p{Letter}]\/v.test('\u03bb'); \/\/ true\n\/[p{Script=Greek}&amp;&amp;p{Letter}]\/v.test('\u0384') \/\/ false\n\/[p{Script=Greek}]\/v.test(\"\u0384\"); \/\/ true\n\n\/\/ Only ascii symbols\n\/[p{Symbol}&amp;&amp;p{ASCII}]\/v.test('\u2713'); \/\/ false\n\/[p{Symbol}]\/v.test('\u2713'); \/\/ true\n<\/code><\/pre>\n<h1 id=\"less-common\">Less Common<\/h1>\n<pre><code class=\"language-typescript\">const flags: string = \/a\/ig.flags; \/\/ \"gi\"\nconst src: string = \/a\/.source; \/\/ \"a\"\n<\/code><\/pre>\n<h2 id=\"stringprototypesearch\">String.prototype.search<\/h2>\n<p style=\"float: right\"><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/String\/search\">String.prototype.search<\/a><\/p>\n<p>A more powerful version of <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/String\/indexOf\"><code>indexOf<\/code><\/a>. Returns <code>-1<\/code> if no match.<\/p>\n<pre><code class=\"language-javascript\">const index: number = \/a\/.search('a');\n<\/code><\/pre>\n<h2 id=\"stringprototypesplit\">String.prototype.split<\/h2>\n<p style=\"float: right\"><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/String\/split\">String.prototype.split<\/a><\/p>\n<p>Usually used in the form of something like <code>'a,b,c'.split(',')<\/code>. But also possible to split on regex matches.<\/p>\n<pre><code class=\"language-javascript\">\"a,b;c\".split(\/,|;\/);\n\/\/ --&gt; ['a', 'b', 'c']\n\n\/\/ Wrap in parentheses to include the separator.\n\"a,b;c\".split(\/(,|;)\/);\n\/\/ --&gt; ['a', ',', 'b', ';', 'c']\n<\/code><\/pre>\n<h2 id=\"regexpprototypelastindex\">RegExp.prototype.lastIndex<\/h2>\n<p style=\"float: right\"><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/RegExp\/lastIndex\">RegExp.prototype.lastIndex<\/a><\/p>\n<p>Used by <code>exec<\/code>, <code>test<\/code>, \u2026 with the global (<code>g<\/code>) flag and for any of the above functions when using the sticky (<code>y<\/code>) flag.<\/p>\n<pre><code class=\"language-javascript\">const input = 'aab';\nconst regex = \/a\/g;\nregex.test(input); \/\/ Returns true. lastIndex is now 1\nregex.test(input); \/\/ Returns true. lastIndex is now 2\nregex.test(input); \/\/ Returns false. lastIndex is reset to 0\n<\/code><\/pre>\n<h1>Also in this series<\/h1>\n<ul>\n<li>This Part: JavaScript RegExp Tutorial<\/li>\n<li>Part 2: <a href=\"\/dotnet\/regex-in-dotnet\/\">.NET Regex Tutorial<\/a><\/li>\n<li>Part 3: <a href=\"\/productivity\/regex-introduction\/\">Regular Expressions: Introduction<\/a><\/li>\n<li>Part 4: <a href=\"\/productivity\/regex-tutorial\/\">Regular Expressions: Tutorial<\/a><\/li>\n<\/ul>\n<h1>Extras<\/h1>\n<p><b>Stuff that came into being during the making of this post<\/b><\/p>\n<ul>\n<li><a href=\"https:\/\/github.com\/itenium-be\/ModernJS\">Jest UnitTests for all ECMAScript features since 2019<\/a><\/li>\n<\/ul>\n<p><b>Other interesting reads<\/b><\/p>\n<ul>\n<li><a href=\"https:\/\/www.smashingmagazine.com\/2024\/08\/history-future-regular-expressions-javascript\/\">Regexes Got Good: The History And Future Of Regular Expressions In JavaScript<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/aloisdg\/awesome-regex\" class=\"github\"><img decoding=\"async\" src=\"https:\/\/img.shields.io\/github\/stars\/aloisdg\/awesome-regex.svg?style=social&#038;label=Star\" \/><\/a><a href=\"https:\/\/github.com\/aloisdg\/awesome-regex\">aloisdg\/awesome-regex<\/a>: A curated collection of awesome Regex libraries, tools, frameworks and software<\/li>\n<li><a href=\"https:\/\/www.rexegg.com\/\">RexEgg.com: The world&#8217;s most tyrannosaurical regex tutorial<\/a><\/li>\n<li><a href=\"http:\/\/2ality.com\/2015\/07\/regexp-es6.html\">New regular expression features in ECMAScript 6 (7\/2015)<\/a><\/li>\n<li><a href=\"https:\/\/regexr.com\/\">regexr.com: Online, open source tool to learn, build, &#038; test regexes<\/a><\/li>\n<li><a href=\"https:\/\/regex101.com\/\">regex101.com: Another online regex test tool<\/a><\/li>\n<\/ul>\n<h1>Updates<\/h1>\n<ul>\n<li> 30 January 2025: Added ES2024 \/\/v flag (UnicodeSets)<\/li>\n<li> 6 October 2023: Added ES2020 &#038; ES2021 RegExp enhancements<\/li>\n<li> 22 May 2023: RegExp.prototype.matchAll was added in ES2020<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>A cheat sheet for the regex syntax in JavaScript.<\/p>\n<p style=\"float: right\"><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Guide\/Regular_Expressions\">MDN RegExp Guide<\/a><\/p>\n<p><strong>TL&amp;DR<\/strong><\/p>\n<pre><code class=\"language-javascript\">\/^$\/.test(''); \/\/ boolean\n'ok'.replace(\/(o)(k)\/g, '$2$1');\n\/\/ Other replacements:\n\/\/ $$ (literal), $&amp; (all), $` (before), $' (after), $&lt;name&gt;\n\nconst matchG = 'aaa'.match(\/a\/g);\nmatchG == ['a', 'a', 'a'];\n\nconst matchNoG = 'str'.match(\/(st)r\/);\nmatchNoG == Object.assign(['str', 'st'], {groups: undefined, index: 0, input: 'str'});\nmatchNoG == \/(st)r\/.exec('str');\n<\/code><\/pre>\n","protected":false},"author":1,"featured_media":2083,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[3],"tags":[13,34],"class_list":["post-1597","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript","tag-cheat-sheet","tag-regex"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>JavaScript RegExp Tutorial - Itenium<\/title>\n<meta name=\"robots\" content=\"noindex, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JavaScript RegExp Tutorial - Itenium\" \/>\n<meta property=\"og:description\" content=\"A cheat sheet for the regex syntax in JavaScript.MDN RegExp GuideTL&amp;DR \/^$\/.test(&#039;&#039;); \/\/ boolean &#039;ok&#039;.replace(\/(o)(k)\/g, &#039;$2$1&#039;); \/\/ Other replacements: \/\/ $$ (literal), $&amp; (all), $` (before), $&#039; (after), $&lt;name&gt; const matchG = &#039;aaa&#039;.match(\/a\/g); matchG == [&#039;a&#039;, &#039;a&#039;, &#039;a&#039;]; const matchNoG = &#039;str&#039;.match(\/(st)r\/); matchNoG == Object.assign([&#039;str&#039;, &#039;st&#039;], {groups: undefined, index: 0, input: &#039;str&#039;}); matchNoG == \/(st)r\/.exec(&#039;str&#039;);\" \/>\n<meta property=\"og:url\" content=\"https:\/\/demo.sidekick.be\/itenium\/blog\/javascript\/regex-in-javascript\/\" \/>\n<meta property=\"og:site_name\" content=\"Itenium\" \/>\n<meta property=\"article:published_time\" content=\"2025-01-29T21:00:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-11-28T12:31:45+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/demo.sidekick.be\/itenium\/wp-content\/uploads\/2025\/11\/when-searching-regular-expressions-on-unsplash.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"360\" \/>\n\t<meta property=\"og:image:height\" content=\"300\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Usdevelop\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Usdevelop\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/demo.sidekick.be\/itenium\/blog\/javascript\/regex-in-javascript\/\",\"url\":\"https:\/\/demo.sidekick.be\/itenium\/blog\/javascript\/regex-in-javascript\/\",\"name\":\"JavaScript RegExp Tutorial - Itenium\",\"isPartOf\":{\"@id\":\"https:\/\/demo.sidekick.be\/itenium\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/demo.sidekick.be\/itenium\/blog\/javascript\/regex-in-javascript\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/demo.sidekick.be\/itenium\/blog\/javascript\/regex-in-javascript\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/demo.sidekick.be\/itenium\/wp-content\/uploads\/2025\/11\/when-searching-regular-expressions-on-unsplash.jpg\",\"datePublished\":\"2025-01-29T21:00:00+00:00\",\"dateModified\":\"2025-11-28T12:31:45+00:00\",\"author\":{\"@id\":\"https:\/\/demo.sidekick.be\/itenium\/#\/schema\/person\/6ab401ce01e858184ee4a8667fe0f022\"},\"breadcrumb\":{\"@id\":\"https:\/\/demo.sidekick.be\/itenium\/blog\/javascript\/regex-in-javascript\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/demo.sidekick.be\/itenium\/blog\/javascript\/regex-in-javascript\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/demo.sidekick.be\/itenium\/blog\/javascript\/regex-in-javascript\/#primaryimage\",\"url\":\"https:\/\/demo.sidekick.be\/itenium\/wp-content\/uploads\/2025\/11\/when-searching-regular-expressions-on-unsplash.jpg\",\"contentUrl\":\"https:\/\/demo.sidekick.be\/itenium\/wp-content\/uploads\/2025\/11\/when-searching-regular-expressions-on-unsplash.jpg\",\"width\":360,\"height\":300},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/demo.sidekick.be\/itenium\/blog\/javascript\/regex-in-javascript\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/demo.sidekick.be\/itenium\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JavaScript RegExp Tutorial\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/demo.sidekick.be\/itenium\/#website\",\"url\":\"https:\/\/demo.sidekick.be\/itenium\/\",\"name\":\"Itenium\",\"description\":\"We build software. We build careers.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/demo.sidekick.be\/itenium\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/demo.sidekick.be\/itenium\/#\/schema\/person\/6ab401ce01e858184ee4a8667fe0f022\",\"name\":\"Usdevelop\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/demo.sidekick.be\/itenium\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/cc8cf9b9e9d5bbe7e8d247907cc9ac8457bbfa2854b52eaddf6529adfe88ceab?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/cc8cf9b9e9d5bbe7e8d247907cc9ac8457bbfa2854b52eaddf6529adfe88ceab?s=96&d=mm&r=g\",\"caption\":\"Usdevelop\"},\"sameAs\":[\"https:\/\/demo.sidekick.be\/itenium\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"JavaScript RegExp Tutorial - Itenium","robots":{"index":"noindex","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"og_locale":"en_US","og_type":"article","og_title":"JavaScript RegExp Tutorial - Itenium","og_description":"A cheat sheet for the regex syntax in JavaScript.MDN RegExp GuideTL&amp;DR \/^$\/.test(''); \/\/ boolean 'ok'.replace(\/(o)(k)\/g, '$2$1'); \/\/ Other replacements: \/\/ $$ (literal), $&amp; (all), $` (before), $' (after), $&lt;name&gt; const matchG = 'aaa'.match(\/a\/g); matchG == ['a', 'a', 'a']; const matchNoG = 'str'.match(\/(st)r\/); matchNoG == Object.assign(['str', 'st'], {groups: undefined, index: 0, input: 'str'}); matchNoG == \/(st)r\/.exec('str');","og_url":"https:\/\/demo.sidekick.be\/itenium\/blog\/javascript\/regex-in-javascript\/","og_site_name":"Itenium","article_published_time":"2025-01-29T21:00:00+00:00","article_modified_time":"2025-11-28T12:31:45+00:00","og_image":[{"width":360,"height":300,"url":"https:\/\/demo.sidekick.be\/itenium\/wp-content\/uploads\/2025\/11\/when-searching-regular-expressions-on-unsplash.jpg","type":"image\/jpeg"}],"author":"Usdevelop","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Usdevelop","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/demo.sidekick.be\/itenium\/blog\/javascript\/regex-in-javascript\/","url":"https:\/\/demo.sidekick.be\/itenium\/blog\/javascript\/regex-in-javascript\/","name":"JavaScript RegExp Tutorial - Itenium","isPartOf":{"@id":"https:\/\/demo.sidekick.be\/itenium\/#website"},"primaryImageOfPage":{"@id":"https:\/\/demo.sidekick.be\/itenium\/blog\/javascript\/regex-in-javascript\/#primaryimage"},"image":{"@id":"https:\/\/demo.sidekick.be\/itenium\/blog\/javascript\/regex-in-javascript\/#primaryimage"},"thumbnailUrl":"https:\/\/demo.sidekick.be\/itenium\/wp-content\/uploads\/2025\/11\/when-searching-regular-expressions-on-unsplash.jpg","datePublished":"2025-01-29T21:00:00+00:00","dateModified":"2025-11-28T12:31:45+00:00","author":{"@id":"https:\/\/demo.sidekick.be\/itenium\/#\/schema\/person\/6ab401ce01e858184ee4a8667fe0f022"},"breadcrumb":{"@id":"https:\/\/demo.sidekick.be\/itenium\/blog\/javascript\/regex-in-javascript\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/demo.sidekick.be\/itenium\/blog\/javascript\/regex-in-javascript\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/demo.sidekick.be\/itenium\/blog\/javascript\/regex-in-javascript\/#primaryimage","url":"https:\/\/demo.sidekick.be\/itenium\/wp-content\/uploads\/2025\/11\/when-searching-regular-expressions-on-unsplash.jpg","contentUrl":"https:\/\/demo.sidekick.be\/itenium\/wp-content\/uploads\/2025\/11\/when-searching-regular-expressions-on-unsplash.jpg","width":360,"height":300},{"@type":"BreadcrumbList","@id":"https:\/\/demo.sidekick.be\/itenium\/blog\/javascript\/regex-in-javascript\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/demo.sidekick.be\/itenium\/"},{"@type":"ListItem","position":2,"name":"JavaScript RegExp Tutorial"}]},{"@type":"WebSite","@id":"https:\/\/demo.sidekick.be\/itenium\/#website","url":"https:\/\/demo.sidekick.be\/itenium\/","name":"Itenium","description":"We build software. We build careers.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/demo.sidekick.be\/itenium\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/demo.sidekick.be\/itenium\/#\/schema\/person\/6ab401ce01e858184ee4a8667fe0f022","name":"Usdevelop","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/demo.sidekick.be\/itenium\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/cc8cf9b9e9d5bbe7e8d247907cc9ac8457bbfa2854b52eaddf6529adfe88ceab?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/cc8cf9b9e9d5bbe7e8d247907cc9ac8457bbfa2854b52eaddf6529adfe88ceab?s=96&d=mm&r=g","caption":"Usdevelop"},"sameAs":["https:\/\/demo.sidekick.be\/itenium"]}]}},"_links":{"self":[{"href":"https:\/\/demo.sidekick.be\/itenium\/wp-json\/wp\/v2\/posts\/1597","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/demo.sidekick.be\/itenium\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/demo.sidekick.be\/itenium\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/demo.sidekick.be\/itenium\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/demo.sidekick.be\/itenium\/wp-json\/wp\/v2\/comments?post=1597"}],"version-history":[{"count":3,"href":"https:\/\/demo.sidekick.be\/itenium\/wp-json\/wp\/v2\/posts\/1597\/revisions"}],"predecessor-version":[{"id":2297,"href":"https:\/\/demo.sidekick.be\/itenium\/wp-json\/wp\/v2\/posts\/1597\/revisions\/2297"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/demo.sidekick.be\/itenium\/wp-json\/wp\/v2\/media\/2083"}],"wp:attachment":[{"href":"https:\/\/demo.sidekick.be\/itenium\/wp-json\/wp\/v2\/media?parent=1597"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/demo.sidekick.be\/itenium\/wp-json\/wp\/v2\/categories?post=1597"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/demo.sidekick.be\/itenium\/wp-json\/wp\/v2\/tags?post=1597"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}