{"route":"/en-US-v0.13.1/reference/foundations/regex/","title":"Regex","description":"Documentation for the Regex type.","part":null,"outline":[{"id":"summary","name":"Summary","children":[]},{"id":"example","name":"Example","children":[]},{"id":"constructor","name":"Constructor","children":[{"id":"constructor-regex","name":"regex","children":[]}]}],"body":{"kind":"type","content":{"name":"regex","title":"Regex","keywords":[],"oneliner":"A regular expression.","details":"<p>A regular expression.</p>\n<p>Can be used as a <a href=\"/en-US-v0.13.1/reference/styling/#show-rules\">show rule selector</a> and with\n<a href=\"/en-US-v0.13.1/reference/foundations/str/\">string methods</a> like <code>find</code>, <code>split</code>, and <code>replace</code>.</p>\n<p><a href=\"https://docs.rs/regex/latest/regex/#syntax\">See here</a> for a specification\nof the supported syntax.</p>\n<h2 id=\"example\">Example</h2>\n<div class=\"previewed-code\"><pre><code><span class=\"typ-comment\">// Works with string methods.</span>\n<span class=\"typ-str\">#</span><span class=\"typ-str\">&quot;a,b;c&quot;</span><span class=\"typ-punct\">.</span><span class=\"typ-func\">split</span><span class=\"typ-punct\">(</span><span class=\"typ-func\">regex</span><span class=\"typ-punct\">(</span><span class=\"typ-str\">&quot;[,;]&quot;</span><span class=\"typ-punct\">)</span><span class=\"typ-punct\">)</span>\n\n<span class=\"typ-comment\">// Works with show rules.</span>\n<span class=\"typ-key\">#</span><span class=\"typ-key\">show</span> <span class=\"typ-func\">regex</span><span class=\"typ-punct\">(</span><span class=\"typ-str\">&quot;\\d+&quot;</span><span class=\"typ-punct\">)</span><span class=\"typ-punct\">:</span> <span class=\"typ-key\">set</span> <span class=\"typ-func\">text</span><span class=\"typ-punct\">(</span>red<span class=\"typ-punct\">)</span>\n\nThe numbers 1 to 10.\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.13.1/assets/52d7d724092529d8f2059dc7991c18f8.png\" alt=\"Preview\"></div></div>","constructor":{"path":[],"name":"regex","title":"Construct","keywords":[],"oneliner":"Create a regular expression from a string.","element":false,"contextual":false,"deprecation":null,"details":"<p>Create a regular expression from a string.</p>","example":null,"self":false,"params":[{"name":"regex","details":"<p>The regular expression as a string.</p>\n<p>Most regex escape sequences just work because they are not valid Typst\nescape sequences. To produce regex escape sequences that are also valid in\nTypst (e.g. <code><span class=\"typ-escape\">\\\\</span></code>), you need to escape twice. Thus, to match a verbatim\nbackslash, you would need to write <code><span class=\"typ-func\">regex</span><span class=\"typ-punct\">(</span><span class=\"typ-str\">&quot;\\\\\\\\&quot;</span><span class=\"typ-punct\">)</span></code>.</p>\n<p>If you need many escape sequences, you can also create a raw element\nand extract its text to use it for your regular expressions:</p>","example":"<p><code><span class=\"typ-func\">regex</span><span class=\"typ-punct\">(</span><span class=\"typ-raw\">`\\d+\\.\\d+\\.\\d+`</span><span class=\"typ-punct\">.</span>text<span class=\"typ-punct\">)</span></code>.</p>","types":["str"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false}],"returns":["regex"],"scope":[]},"scope":[]}}}