{"componentChunkName":"component---src-templates-default-template-tsx","path":"/ki-syntax/functions/regex/","result":{"data":{"asciidoc":{"id":"152b57c2-2ee9-5464-b626-8b57bf74cdd1","html":"<div id=\"toc\" class=\"toc\">\n<div id=\"toctitle\">Table of Contents</div>\n<ul class=\"sectlevel1\">\n<li><a href=\"#definition\">Definition</a></li>\n<li><a href=\"#usage\">Usage</a></li>\n<li><a href=\"#example\">Example</a></li>\n<li><a href=\"#case-insensitive-matching\">Case Insensitive Matching</a></li>\n</ul>\n</div>\n<div class=\"sect1\">\n<h2 id=\"definition\">Definition</h2>\n<div class=\"sectionbody\">\n<div class=\"paragraph\">\n<p>This can by used to extract part(s) of a string using a regular expression.</p>\n</div>\n<div class=\"admonitionblock note\">\n<table>\n<tr>\n<td class=\"icon\">\n<i class=\"fa icon-note\" title=\"Note\"></i>\n</td>\n<td class=\"content\">\nThe internal Elixir regex library is used, which is based on PCRE (Perl Compatible Regular Expressions).\nPlease refer to the <a href=\"https://hexdocs.pm/elixir/Regex.html\">Elixir documentation</a> for further details.\n</td>\n</tr>\n</table>\n</div>\n<div class=\"admonitionblock tip\">\n<table>\n<tr>\n<td class=\"icon\">\n<i class=\"fa icon-tip\" title=\"Tip\"></i>\n</td>\n<td class=\"content\">\nIf the string is already being matched in an <code>on</code> or <code>when</code> section, a named capture in that match is usually the better choice. It avoids writing the pattern twice and can extract several submatches at once. See <a href=\"/7.0/ki-syntax/definitions/matching.html#named-captures/\">Named captures</a>.\n</td>\n</tr>\n</table>\n</div>\n</div>\n</div>\n<div class=\"sect1\">\n<h2 id=\"usage\">Usage</h2>\n<div class=\"sectionbody\">\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight\"><code class=\"language-elixir\" data-lang=\"elixir\">result: LOCAL::RESULT = regex(\"&lt;text to be matched&gt;\", expression: \"&lt;regex expression&gt;\")</code></pre>\n</div>\n</div>\n<table class=\"tableblock frame-all grid-all stretch\">\n<caption class=\"title\">Table 1. Arguments</caption>\n<colgroup>\n<col style=\"width: 25%;\">\n<col style=\"width: 25%;\">\n<col style=\"width: 25%;\">\n<col style=\"width: 25%;\">\n</colgroup>\n<thead>\n<tr>\n<th class=\"tableblock halign-left valign-top\">Position</th>\n<th class=\"tableblock halign-left valign-top\">Keyword</th>\n<th class=\"tableblock halign-left valign-top\">Required</th>\n<th class=\"tableblock halign-left valign-top\">Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td class=\"tableblock halign-left valign-top\"><p class=\"tableblock\">1</p></td>\n<td class=\"tableblock halign-left valign-top\"><p class=\"tableblock\">string</p></td>\n<td class=\"tableblock halign-left valign-top\"><p class=\"tableblock\">X</p></td>\n<td class=\"tableblock halign-left valign-top\"><p class=\"tableblock\">String onto which the regex is applied</p></td>\n</tr>\n<tr>\n<td class=\"tableblock halign-left valign-top\"><p class=\"tableblock\">2</p></td>\n<td class=\"tableblock halign-left valign-top\"><p class=\"tableblock\">expression</p></td>\n<td class=\"tableblock halign-left valign-top\"><p class=\"tableblock\">X</p></td>\n<td class=\"tableblock halign-left valign-top\"><p class=\"tableblock\">Regular Expression, needs at least one SubMatch-Pattern. e.g. \"Value: (0-9+) Seconds\"</p></td>\n</tr>\n<tr>\n<td class=\"tableblock halign-left valign-top\"><p class=\"tableblock\">3</p></td>\n<td class=\"tableblock halign-left valign-top\"><p class=\"tableblock\">options</p></td>\n<td class=\"tableblock halign-left valign-top\"></td>\n<td class=\"tableblock halign-left valign-top\"><p class=\"tableblock\">Modifiers for creating the Regex, e.g. \"i\". A full list of modifiers is available in the <a href=\"https://hexdocs.pm/elixir/Regex.html#module-modifiers\">Elixir documentation</a>.</p></td>\n</tr>\n</tbody>\n</table>\n<div class=\"paragraph\">\n<p>&#160;<br></p>\n</div>\n<table class=\"tableblock frame-all grid-all stretch\">\n<caption class=\"title\">Table 2. Return Values</caption>\n<colgroup>\n<col style=\"width: 50%;\">\n<col style=\"width: 50%;\">\n</colgroup>\n<thead>\n<tr>\n<th class=\"tableblock halign-left valign-top\">Tag</th>\n<th class=\"tableblock halign-left valign-top\">Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td class=\"tableblock halign-left valign-top\"><p class=\"tableblock\">result</p></td>\n<td class=\"tableblock halign-left valign-top\"><p class=\"tableblock\">Extracted substring</p></td>\n</tr>\n<tr>\n<td class=\"tableblock halign-left valign-top\"><p class=\"tableblock\">resultN</p></td>\n<td class=\"tableblock halign-left valign-top\"><p class=\"tableblock\">Nth extracted substring (optional depending on regex)</p></td>\n</tr>\n</tbody>\n</table>\n</div>\n</div>\n<div class=\"sect1\">\n<h2 id=\"example\">Example</h2>\n<div class=\"sectionbody\">\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight\"><code class=\"language-elixir\" data-lang=\"elixir\">result: LOCAL::RESULT = regex(\"Here is a hidden value 47.11 inside\", expression: \".*value ([0-9.]+) .*\")</code></pre>\n</div>\n</div>\n<div class=\"paragraph\">\n<p>In this example we match a \"string\" that contains: \"Here is a hidden\nvalue 47.11 inside\". We want to extract the number value from this so\nour regex matches only numbers with a decimal point.</p>\n</div>\n<div class=\"paragraph\">\n<p>The resulting match of the regex is \"47.11\". This value is then stored\nin the variable <code>RESULT</code> in the LOCAL scope.</p>\n</div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight\"><code class=\"language-elixir\" data-lang=\"elixir\">result: LOCAL::RESULT = regex(\"${-message}\", expression: \".*value .*\")</code></pre>\n</div>\n</div>\n<div class=\"paragraph\">\n<p>In this example, the \"-\" character is a string modifier that converts the entire string to lowercase.\nFor more string modifiers go <a href=\"https://user-guides.engine.datagroup.de/7.0/ki-syntax/definitions/varstrings/#_string_modifiers\">here\n</a>.</p>\n</div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight\"><code class=\"language-elixir\" data-lang=\"elixir\">result: LOCAL::MAJOR, result2: LOCAL::MINOR, result3: LOCAL::PATCH = regex(\"Version 4.7.0\", \"([0-9]+)\\.([0-9]+)\\.([0-9]+)\")</code></pre>\n</div>\n</div>\n<div class=\"paragraph\">\n<p>In this example, a version number is extracted with a multi-submatch regex, so major, minor and patch numbers are extracted separately.</p>\n</div>\n</div>\n</div>\n<div class=\"sect1\">\n<h2 id=\"case-insensitive-matching\">Case Insensitive Matching</h2>\n<div class=\"sectionbody\">\n<div class=\"paragraph\">\n<p>In order to perform case-insensitive matching, you can either use the options argument or a regex literal with options:</p>\n</div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight\"><code class=\"language-elixir\" data-lang=\"elixir\"># Using options argument\nresult: LOCAL::RESULT = regex(\"VaLuE: 42.0\", expression: \"value ([0-9.]+)\", options: \"i\")\n# Using regex literal\nresult: LOCAL::RESULT = regex(\"VaLuE: 42.0\", expression: /value ([0-9.]+)/i)\n\n# The options argument does not override the options of a regex\n# literal, so this is has the same result as the last line:\nresult: LOCAL::RESULT = regex(\"VaLuE: 42.0\", expression: /value ([0-9.]+)/i, options: \"\")</code></pre>\n</div>\n</div>\n</div>\n</div>","document":{"main":"regex","title":"regex","subtitle":""},"fields":{"toc":true,"location":["ki-syntax","functions","regex"]}},"sidebarYaml":{"id":"6f28bdca-d703-5e79-ae00-b0508f8ee82a","showIndex":true}},"pageContext":{"id":"152b57c2-2ee9-5464-b626-8b57bf74cdd1","parent":"ki-syntax"}},"staticQueryHashes":["1010459453","1010459453","2356112386","2356112386","2603905930","2603905930","3026652197","3026652197","3167850324","3167850324","63159454","63159454"]}