{"route":"/en-US-v0.14.1/reference/foundations/str/","title":"String","description":"Documentation for the String type.","part":null,"outline":[{"id":"summary","name":"Summary","children":[]},{"id":"example","name":"Example","children":[]},{"id":"escapes","name":"Escapes","children":[]},{"id":"constructor","name":"Constructor","children":[{"id":"constructor-value","name":"value","children":[]},{"id":"constructor-base","name":"base","children":[]}]},{"id":"definitions","name":"Definitions","children":[{"id":"definitions-len","name":"Length","children":[]},{"id":"definitions-first","name":"First","children":[{"id":"definitions-first-default","name":"default","children":[]}]},{"id":"definitions-last","name":"Last","children":[{"id":"definitions-last-default","name":"default","children":[]}]},{"id":"definitions-at","name":"At","children":[{"id":"definitions-at-index","name":"index","children":[]},{"id":"definitions-at-default","name":"default","children":[]}]},{"id":"definitions-slice","name":"Slice","children":[{"id":"definitions-slice-start","name":"start","children":[]},{"id":"definitions-slice-end","name":"end","children":[]},{"id":"definitions-slice-count","name":"count","children":[]}]},{"id":"definitions-clusters","name":"Clusters","children":[]},{"id":"definitions-codepoints","name":"Codepoints","children":[]},{"id":"definitions-to-unicode","name":"To Unicode","children":[{"id":"definitions-to-unicode-character","name":"character","children":[]}]},{"id":"definitions-from-unicode","name":"From Unicode","children":[{"id":"definitions-from-unicode-value","name":"value","children":[]}]},{"id":"definitions-normalize","name":"Normalize","children":[{"id":"definitions-normalize-form","name":"form","children":[]}]},{"id":"definitions-contains","name":"Contains","children":[{"id":"definitions-contains-pattern","name":"pattern","children":[]}]},{"id":"definitions-starts-with","name":"Starts With","children":[{"id":"definitions-starts-with-pattern","name":"pattern","children":[]}]},{"id":"definitions-ends-with","name":"Ends With","children":[{"id":"definitions-ends-with-pattern","name":"pattern","children":[]}]},{"id":"definitions-find","name":"Find","children":[{"id":"definitions-find-pattern","name":"pattern","children":[]}]},{"id":"definitions-position","name":"Position","children":[{"id":"definitions-position-pattern","name":"pattern","children":[]}]},{"id":"definitions-match","name":"Match","children":[{"id":"definitions-match-pattern","name":"pattern","children":[]}]},{"id":"definitions-matches","name":"Matches","children":[{"id":"definitions-matches-pattern","name":"pattern","children":[]}]},{"id":"definitions-replace","name":"Replace","children":[{"id":"definitions-replace-pattern","name":"pattern","children":[]},{"id":"definitions-replace-replacement","name":"replacement","children":[]},{"id":"definitions-replace-count","name":"count","children":[]}]},{"id":"definitions-trim","name":"Trim","children":[{"id":"definitions-trim-pattern","name":"pattern","children":[]},{"id":"definitions-trim-at","name":"at","children":[]},{"id":"definitions-trim-repeat","name":"repeat","children":[]}]},{"id":"definitions-split","name":"Split","children":[{"id":"definitions-split-pattern","name":"pattern","children":[]}]},{"id":"definitions-rev","name":"Reverse","children":[]}]}],"body":{"kind":"type","content":{"name":"str","title":"String","keywords":[],"oneliner":"A sequence of Unicode codepoints.","details":"<p>A sequence of Unicode codepoints.</p>\n<p>You can iterate over the grapheme clusters of the string using a <a href=\"/en-US-v0.14.1/reference/scripting/#loops\">for\nloop</a>. Grapheme clusters are basically characters but\nkeep together things that belong together, e.g. multiple codepoints that\ntogether form a flag emoji. Strings can be added with the <code>+</code> operator,\n<a href=\"/en-US-v0.14.1/reference/scripting/#blocks\">joined together</a> and multiplied with integers.</p>\n<p>Typst provides utility methods for string manipulation. Many of these\nmethods (e.g., <a href=\"/en-US-v0.14.1/reference/foundations/str/#definitions-split\"><code>split</code></a>, <a href=\"/en-US-v0.14.1/reference/foundations/str/#definitions-trim\"><code>trim</code></a> and\n<a href=\"/en-US-v0.14.1/reference/foundations/str/#definitions-replace\"><code>replace</code></a>) operate on <em>patterns:</em> A pattern can be either a\nstring or a <a href=\"/en-US-v0.14.1/reference/foundations/regex/\">regular expression</a>. This makes the methods quite\nversatile.</p>\n<p>All lengths and indices are expressed in terms of UTF-8 bytes. Indices are\nzero-based and negative indices wrap around to the end of the string.</p>\n<p>You can convert a value to a string with this type's constructor.</p>\n<h2 id=\"example\">Example</h2>\n<div class=\"previewed-code\"><pre><code><span class=\"typ-str\">#</span><span class=\"typ-str\">&quot;hello world!&quot;</span> <span class=\"typ-escape\">\\</span>\n<span class=\"typ-str\">#</span><span class=\"typ-str\">&quot;\\&quot;hello\\n  world\\&quot;!&quot;</span> <span class=\"typ-escape\">\\</span>\n<span class=\"typ-str\">#</span><span class=\"typ-str\">&quot;1 2 3&quot;</span><span class=\"typ-punct\">.</span><span class=\"typ-func\">split</span><span class=\"typ-punct\">(</span><span class=\"typ-punct\">)</span> <span class=\"typ-escape\">\\</span>\n<span class=\"typ-str\">#</span><span class=\"typ-str\">&quot;1,2;3&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> <span class=\"typ-escape\">\\</span>\n<span class=\"typ-punct\">#</span><span class=\"typ-punct\">(</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-key\">in</span> <span class=\"typ-str\">&quot;ten euros&quot;</span><span class=\"typ-punct\">)</span> <span class=\"typ-escape\">\\</span>\n<span class=\"typ-punct\">#</span><span class=\"typ-punct\">(</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-key\">in</span> <span class=\"typ-str\">&quot;10 euros&quot;</span><span class=\"typ-punct\">)</span>\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.14.1/assets/80af3d02723d93b772f369bd4771758e.png\" alt=\"Preview\"></div></div>\n<h2 id=\"escapes\">Escape sequences</h2>\n<p>Just like in markup, you can escape a few symbols in strings:</p>\n<ul>\n<li><code><span class=\"typ-escape\">\\\\</span></code> for a backslash</li>\n<li><code><span class=\"typ-escape\">\\&quot;</span></code> for a quote</li>\n<li><code><span class=\"typ-escape\">\\n</span></code> for a newline</li>\n<li><code><span class=\"typ-escape\">\\r</span></code> for a carriage return</li>\n<li><code><span class=\"typ-escape\">\\t</span></code> for a tab</li>\n<li><code><span class=\"typ-escape\">\\u{1f600}</span></code> for a hexadecimal Unicode escape sequence</li>\n</ul>","constructor":{"path":[],"name":"str","title":"Construct","keywords":[],"oneliner":"Converts a value to a string.","element":false,"contextual":false,"deprecationMessage":null,"deprecationUntil":null,"details":[{"kind":"html","content":"<p>Converts a value to a string.</p>\n<ul>\n<li>Integers are formatted in base 10. This can be overridden with the\noptional <code>base</code> parameter.</li>\n<li>Floats are formatted in base 10 and never in exponential notation.</li>\n<li>Negative integers and floats are formatted with the Unicode minus sign\n(&quot;−&quot; U+2212) instead of the ASCII minus sign (&quot;-&quot; U+002D).</li>\n<li>From labels the name is extracted.</li>\n<li>Bytes are decoded as UTF-8.</li>\n</ul>\n<p>If you wish to convert from and to Unicode code points, see the\n<a href=\"/en-US-v0.14.1/reference/foundations/str/#definitions-to-unicode\"><code>to-unicode</code></a> and <a href=\"/en-US-v0.14.1/reference/foundations/str/#definitions-from-unicode\"><code>from-unicode</code></a>\nfunctions.</p>"},{"kind":"example","content":{"body":"<div class=\"previewed-code\"><pre><code><span class=\"typ-func\">#</span><span class=\"typ-func\">str</span><span class=\"typ-punct\">(</span><span class=\"typ-num\">10</span><span class=\"typ-punct\">)</span> <span class=\"typ-escape\">\\</span>\n<span class=\"typ-func\">#</span><span class=\"typ-func\">str</span><span class=\"typ-punct\">(</span><span class=\"typ-num\">4000</span><span class=\"typ-punct\">,</span> base<span class=\"typ-punct\">:</span> <span class=\"typ-num\">16</span><span class=\"typ-punct\">)</span> <span class=\"typ-escape\">\\</span>\n<span class=\"typ-func\">#</span><span class=\"typ-func\">str</span><span class=\"typ-punct\">(</span><span class=\"typ-num\">2.7</span><span class=\"typ-punct\">)</span> <span class=\"typ-escape\">\\</span>\n<span class=\"typ-func\">#</span><span class=\"typ-func\">str</span><span class=\"typ-punct\">(</span><span class=\"typ-num\">1e8</span><span class=\"typ-punct\">)</span> <span class=\"typ-escape\">\\</span>\n<span class=\"typ-func\">#</span><span class=\"typ-func\">str</span><span class=\"typ-punct\">(</span><span class=\"typ-label\">&lt;intro&gt;</span><span class=\"typ-punct\">)</span>\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.14.1/assets/d3a8d1f73f9f3fe3387aef170763059c.png\" alt=\"Preview\"></div></div>","title":null}}],"self":false,"params":[{"name":"value","details":[{"kind":"html","content":"<p>The value that should be converted to a string.</p>"}],"types":["int","float","str","bytes","label","decimal","version","type"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false},{"name":"base","details":[{"kind":"html","content":"<p>The base (radix) to display integers in, between 2 and 36.</p>"}],"types":["int"],"strings":[],"default":"<code><span class=\"typ-num\">10</span></code>","positional":false,"named":true,"required":false,"variadic":false,"settable":false}],"returns":["str"],"scope":[]},"scope":[{"path":["str"],"name":"len","title":"Length","keywords":[],"oneliner":"The length of the string in UTF-8 encoded bytes.","element":false,"contextual":false,"deprecationMessage":null,"deprecationUntil":null,"details":[{"kind":"html","content":"<p>The length of the string in UTF-8 encoded bytes.</p>"}],"self":true,"params":[],"returns":["int"],"scope":[]},{"path":["str"],"name":"first","title":"First","keywords":[],"oneliner":"Extracts the first grapheme cluster of the string.","element":false,"contextual":false,"deprecationMessage":null,"deprecationUntil":null,"details":[{"kind":"html","content":"<p>Extracts the first grapheme cluster of the string.</p>\n<p>Returns the provided default value if the string is empty or fails with\nan error if no default value was specified.</p>"}],"self":true,"params":[{"name":"default","details":[{"kind":"html","content":"<p>A default value to return if the string is empty.</p>"}],"types":["str"],"strings":[],"default":null,"positional":false,"named":true,"required":false,"variadic":false,"settable":false}],"returns":["str"],"scope":[]},{"path":["str"],"name":"last","title":"Last","keywords":[],"oneliner":"Extracts the last grapheme cluster of the string.","element":false,"contextual":false,"deprecationMessage":null,"deprecationUntil":null,"details":[{"kind":"html","content":"<p>Extracts the last grapheme cluster of the string.</p>\n<p>Returns the provided default value if the string is empty or fails with\nan error if no default value was specified.</p>"}],"self":true,"params":[{"name":"default","details":[{"kind":"html","content":"<p>A default value to return if the string is empty.</p>"}],"types":["str"],"strings":[],"default":null,"positional":false,"named":true,"required":false,"variadic":false,"settable":false}],"returns":["str"],"scope":[]},{"path":["str"],"name":"at","title":"At","keywords":[],"oneliner":"Extracts the first grapheme cluster after the specified index.","element":false,"contextual":false,"deprecationMessage":null,"deprecationUntil":null,"details":[{"kind":"html","content":"<p>Extracts the first grapheme cluster after the specified index. Returns\nthe default value if the index is out of bounds or fails with an error\nif no default value was specified.</p>"}],"self":true,"params":[{"name":"index","details":[{"kind":"html","content":"<p>The byte index. If negative, indexes from the back.</p>"}],"types":["int"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false},{"name":"default","details":[{"kind":"html","content":"<p>A default value to return if the index is out of bounds.</p>"}],"types":["any"],"strings":[],"default":null,"positional":false,"named":true,"required":false,"variadic":false,"settable":false}],"returns":["any"],"scope":[]},{"path":["str"],"name":"slice","title":"Slice","keywords":[],"oneliner":"Extracts a substring of the string.","element":false,"contextual":false,"deprecationMessage":null,"deprecationUntil":null,"details":[{"kind":"html","content":"<p>Extracts a substring of the string.\nFails with an error if the start or end index is out of bounds.</p>"}],"self":true,"params":[{"name":"start","details":[{"kind":"html","content":"<p>The start byte index (inclusive). If negative, indexes from the\nback.</p>"}],"types":["int"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false},{"name":"end","details":[{"kind":"html","content":"<p>The end byte index (exclusive). If omitted, the whole slice until\nthe end of the string is extracted. If negative, indexes from the\nback.</p>"}],"types":["none","int"],"strings":[],"default":"<code><span class=\"typ-key\">none</span></code>","positional":true,"named":false,"required":false,"variadic":false,"settable":false},{"name":"count","details":[{"kind":"html","content":"<p>The number of bytes to extract. This is equivalent to passing\n<code>start + count</code> as the <code>end</code> position. Mutually exclusive with <code>end</code>.</p>"}],"types":["int"],"strings":[],"default":null,"positional":false,"named":true,"required":false,"variadic":false,"settable":false}],"returns":["str"],"scope":[]},{"path":["str"],"name":"clusters","title":"Clusters","keywords":[],"oneliner":"Returns the grapheme clusters of the string as an array of substrings.","element":false,"contextual":false,"deprecationMessage":null,"deprecationUntil":null,"details":[{"kind":"html","content":"<p>Returns the grapheme clusters of the string as an array of substrings.</p>"}],"self":true,"params":[],"returns":["array"],"scope":[]},{"path":["str"],"name":"codepoints","title":"Codepoints","keywords":[],"oneliner":"Returns the Unicode codepoints of the string as an array of substrings.","element":false,"contextual":false,"deprecationMessage":null,"deprecationUntil":null,"details":[{"kind":"html","content":"<p>Returns the Unicode codepoints of the string as an array of substrings.</p>"}],"self":true,"params":[],"returns":["array"],"scope":[]},{"path":["str"],"name":"to-unicode","title":"To Unicode","keywords":[],"oneliner":"Converts a character into its corresponding code point.","element":false,"contextual":false,"deprecationMessage":null,"deprecationUntil":null,"details":[{"kind":"html","content":"<p>Converts a character into its corresponding code point.</p>"},{"kind":"example","content":{"body":"<div class=\"previewed-code\"><pre><code><span class=\"typ-str\">#</span><span class=\"typ-str\">&quot;a&quot;</span><span class=\"typ-punct\">.</span><span class=\"typ-func\">to-unicode</span><span class=\"typ-punct\">(</span><span class=\"typ-punct\">)</span> <span class=\"typ-escape\">\\</span>\n<span class=\"typ-punct\">#</span><span class=\"typ-punct\">(</span><span class=\"typ-str\">&quot;a\\u{0300}&quot;</span>\n   <span class=\"typ-punct\">.</span><span class=\"typ-func\">codepoints</span><span class=\"typ-punct\">(</span><span class=\"typ-punct\">)</span>\n   <span class=\"typ-punct\">.</span><span class=\"typ-func\">map</span><span class=\"typ-punct\">(</span>str<span class=\"typ-punct\">.</span>to-unicode<span class=\"typ-punct\">)</span><span class=\"typ-punct\">)</span>\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.14.1/assets/ab9d2dcfa58024f9f0b4109859b1eb23.png\" alt=\"Preview\"></div></div>","title":null}}],"self":false,"params":[{"name":"character","details":[{"kind":"html","content":"<p>The character that should be converted.</p>"}],"types":["str"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false}],"returns":["int"],"scope":[]},{"path":["str"],"name":"from-unicode","title":"From Unicode","keywords":[],"oneliner":"Converts a unicode code point into its corresponding string.","element":false,"contextual":false,"deprecationMessage":null,"deprecationUntil":null,"details":[{"kind":"html","content":"<p>Converts a unicode code point into its corresponding string.</p>"},{"kind":"example","content":{"body":"<div class=\"previewed-code\"><pre><code><span class=\"typ-pol\">#</span><span class=\"typ-pol\">str</span><span class=\"typ-punct\">.</span><span class=\"typ-func\">from-unicode</span><span class=\"typ-punct\">(</span><span class=\"typ-num\">97</span><span class=\"typ-punct\">)</span>\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.14.1/assets/bcdcdcb063b865dfeef8fe2a367c6b0d.png\" alt=\"Preview\"></div></div>","title":null}}],"self":false,"params":[{"name":"value","details":[{"kind":"html","content":"<p>The code point that should be converted.</p>"}],"types":["int"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false}],"returns":["str"],"scope":[]},{"path":["str"],"name":"normalize","title":"Normalize","keywords":[],"oneliner":"Normalizes the string to the given Unicode normal form.","element":false,"contextual":false,"deprecationMessage":null,"deprecationUntil":null,"details":[{"kind":"html","content":"<p>Normalizes the string to the given Unicode normal form.</p>\n<p>This is useful when manipulating strings containing Unicode combining\ncharacters.</p>"},{"kind":"example","content":{"body":"<pre><code><span class=\"typ-pol\">#</span><span class=\"typ-pol\">assert</span><span class=\"typ-punct\">.</span><span class=\"typ-func\">eq</span><span class=\"typ-punct\">(</span><span class=\"typ-str\">&quot;é&quot;</span><span class=\"typ-punct\">.</span><span class=\"typ-func\">normalize</span><span class=\"typ-punct\">(</span>form<span class=\"typ-punct\">:</span> <span class=\"typ-str\">&quot;nfd&quot;</span><span class=\"typ-punct\">)</span><span class=\"typ-punct\">,</span> <span class=\"typ-str\">&quot;e\\u{0301}&quot;</span><span class=\"typ-punct\">)</span>\n<span class=\"typ-pol\">#</span><span class=\"typ-pol\">assert</span><span class=\"typ-punct\">.</span><span class=\"typ-func\">eq</span><span class=\"typ-punct\">(</span><span class=\"typ-str\">&quot;ſ́&quot;</span><span class=\"typ-punct\">.</span><span class=\"typ-func\">normalize</span><span class=\"typ-punct\">(</span>form<span class=\"typ-punct\">:</span> <span class=\"typ-str\">&quot;nfkc&quot;</span><span class=\"typ-punct\">)</span><span class=\"typ-punct\">,</span> <span class=\"typ-str\">&quot;ś&quot;</span><span class=\"typ-punct\">)</span>\n</code></pre>","title":null}}],"self":true,"params":[{"name":"form","details":[],"types":["str"],"strings":[{"string":"nfc","details":"<p>Canonical composition where e.g. accented letters are turned into a\nsingle Unicode codepoint.</p>"},{"string":"nfd","details":"<p>Canonical decomposition where e.g. accented letters are split into a\nseparate base and diacritic.</p>"},{"string":"nfkc","details":"<p>Like NFC, but using the Unicode compatibility decompositions.</p>"},{"string":"nfkd","details":"<p>Like NFD, but using the Unicode compatibility decompositions.</p>"}],"default":"<code><span class=\"typ-str\">&quot;nfc&quot;</span></code>","positional":false,"named":true,"required":false,"variadic":false,"settable":false}],"returns":["str"],"scope":[]},{"path":["str"],"name":"contains","title":"Contains","keywords":[],"oneliner":"Whether the string contains the specified pattern.","element":false,"contextual":false,"deprecationMessage":null,"deprecationUntil":null,"details":[{"kind":"html","content":"<p>Whether the string contains the specified pattern.</p>\n<p>This method also has dedicated syntax: You can write <code><span class=\"typ-str\">&quot;bc&quot;</span> <span class=\"typ-key\">in</span> <span class=\"typ-str\">&quot;abcd&quot;</span></code>\ninstead of <code><span class=\"typ-str\">&quot;abcd&quot;</span><span class=\"typ-punct\">.</span><span class=\"typ-func\">contains</span><span class=\"typ-punct\">(</span><span class=\"typ-str\">&quot;bc&quot;</span><span class=\"typ-punct\">)</span></code>.</p>"}],"self":true,"params":[{"name":"pattern","details":[{"kind":"html","content":"<p>The pattern to search for.</p>"}],"types":["str","regex"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false}],"returns":["bool"],"scope":[]},{"path":["str"],"name":"starts-with","title":"Starts With","keywords":[],"oneliner":"Whether the string starts with the specified pattern.","element":false,"contextual":false,"deprecationMessage":null,"deprecationUntil":null,"details":[{"kind":"html","content":"<p>Whether the string starts with the specified pattern.</p>"}],"self":true,"params":[{"name":"pattern","details":[{"kind":"html","content":"<p>The pattern the string might start with.</p>"}],"types":["str","regex"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false}],"returns":["bool"],"scope":[]},{"path":["str"],"name":"ends-with","title":"Ends With","keywords":[],"oneliner":"Whether the string ends with the specified pattern.","element":false,"contextual":false,"deprecationMessage":null,"deprecationUntil":null,"details":[{"kind":"html","content":"<p>Whether the string ends with the specified pattern.</p>"}],"self":true,"params":[{"name":"pattern","details":[{"kind":"html","content":"<p>The pattern the string might end with.</p>"}],"types":["str","regex"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false}],"returns":["bool"],"scope":[]},{"path":["str"],"name":"find","title":"Find","keywords":[],"oneliner":"Searches for the specified pattern in the string and returns the first match as a string or `{none}` if there is no match.","element":false,"contextual":false,"deprecationMessage":null,"deprecationUntil":null,"details":[{"kind":"html","content":"<p>Searches for the specified pattern in the string and returns the first\nmatch as a string or <code><span class=\"typ-key\">none</span></code> if there is no match.</p>"}],"self":true,"params":[{"name":"pattern","details":[{"kind":"html","content":"<p>The pattern to search for.</p>"}],"types":["str","regex"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false}],"returns":["none","str"],"scope":[]},{"path":["str"],"name":"position","title":"Position","keywords":[],"oneliner":"Searches for the specified pattern in the string and returns the index of the first match as an integer or `{none}` if there is no match.","element":false,"contextual":false,"deprecationMessage":null,"deprecationUntil":null,"details":[{"kind":"html","content":"<p>Searches for the specified pattern in the string and returns the index\nof the first match as an integer or <code><span class=\"typ-key\">none</span></code> if there is no match.</p>"}],"self":true,"params":[{"name":"pattern","details":[{"kind":"html","content":"<p>The pattern to search for.</p>"}],"types":["str","regex"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false}],"returns":["none","int"],"scope":[]},{"path":["str"],"name":"match","title":"Match","keywords":[],"oneliner":"Searches for the specified pattern in the string and returns a dictionary with details about the first match or `{none}` if there is no match.","element":false,"contextual":false,"deprecationMessage":null,"deprecationUntil":null,"details":[{"kind":"html","content":"<p>Searches for the specified pattern in the string and returns a\ndictionary with details about the first match or <code><span class=\"typ-key\">none</span></code> if there is no\nmatch.</p>\n<p>The returned dictionary has the following keys:</p>\n<ul>\n<li><code>start</code>: The start offset of the match</li>\n<li><code>end</code>: The end offset of the match</li>\n<li><code>text</code>: The text that matched.</li>\n<li><code>captures</code>: An array containing a string for each matched capturing\ngroup. The first item of the array contains the first matched\ncapturing, not the whole match! This is empty unless the <code>pattern</code> was\na regex with capturing groups.</li>\n</ul>"},{"kind":"example","content":{"body":"<div class=\"previewed-code\"><pre><code><span class=\"typ-key\">#</span><span class=\"typ-key\">let</span> pat <span class=\"typ-op\">=</span> <span class=\"typ-func\">regex</span><span class=\"typ-punct\">(</span><span class=\"typ-str\">&quot;not (a|an) (apple|cat)&quot;</span><span class=\"typ-punct\">)</span>\n<span class=\"typ-str\">#</span><span class=\"typ-str\">&quot;I&#39;m a doctor, not an apple.&quot;</span><span class=\"typ-punct\">.</span><span class=\"typ-func\">match</span><span class=\"typ-punct\">(</span>pat<span class=\"typ-punct\">)</span> <span class=\"typ-escape\">\\</span>\n<span class=\"typ-str\">#</span><span class=\"typ-str\">&quot;I am not a cat!&quot;</span><span class=\"typ-punct\">.</span><span class=\"typ-func\">match</span><span class=\"typ-punct\">(</span>pat<span class=\"typ-punct\">)</span>\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.14.1/assets/2589c9739f95e5904f0e8d7a343e835a.png\" alt=\"Preview\"></div></div>","title":"Shape of the returned dictionary"}},{"kind":"example","content":{"body":"<div class=\"previewed-code\"><pre><code><span class=\"typ-pol\">#</span><span class=\"typ-pol\">assert</span><span class=\"typ-punct\">.</span><span class=\"typ-func\">eq</span><span class=\"typ-punct\">(</span><span class=\"typ-str\">&quot;Is there a&quot;</span><span class=\"typ-punct\">.</span><span class=\"typ-func\">match</span><span class=\"typ-punct\">(</span><span class=\"typ-str\">&quot;for this?&quot;</span><span class=\"typ-punct\">)</span><span class=\"typ-punct\">,</span> <span class=\"typ-key\">none</span><span class=\"typ-punct\">)</span>\n<span class=\"typ-str\">#</span><span class=\"typ-str\">&quot;The time of my life.&quot;</span><span class=\"typ-punct\">.</span><span class=\"typ-func\">match</span><span class=\"typ-punct\">(</span><span class=\"typ-func\">regex</span><span class=\"typ-punct\">(</span><span class=\"typ-str\">&quot;[mit]+e&quot;</span><span class=\"typ-punct\">)</span><span class=\"typ-punct\">)</span>\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.14.1/assets/82bd9e34267a90aa0c53d7881294a78.png\" alt=\"Preview\"></div></div>","title":"Different kinds of patterns"}}],"self":true,"params":[{"name":"pattern","details":[{"kind":"html","content":"<p>The pattern to search for.</p>"}],"types":["str","regex"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false}],"returns":["none","dictionary"],"scope":[]},{"path":["str"],"name":"matches","title":"Matches","keywords":[],"oneliner":"Searches for the specified pattern in the string and returns an array of dictionaries with details about all matches.","element":false,"contextual":false,"deprecationMessage":null,"deprecationUntil":null,"details":[{"kind":"html","content":"<p>Searches for the specified pattern in the string and returns an array of\ndictionaries with details about all matches. For details about the\nreturned dictionaries, see <a href=\"/en-US-v0.14.1/reference/foundations/str/#definitions-match\">above</a>.</p>"},{"kind":"example","content":{"body":"<div class=\"previewed-code\"><pre><code><span class=\"typ-str\">#</span><span class=\"typ-str\">&quot;Day by Day.&quot;</span><span class=\"typ-punct\">.</span><span class=\"typ-func\">matches</span><span class=\"typ-punct\">(</span><span class=\"typ-str\">&quot;Day&quot;</span><span class=\"typ-punct\">)</span>\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.14.1/assets/66adbcbd2e7592ad6a07b06db355a074.png\" alt=\"Preview\"></div></div>","title":null}}],"self":true,"params":[{"name":"pattern","details":[{"kind":"html","content":"<p>The pattern to search for.</p>"}],"types":["str","regex"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false}],"returns":["array"],"scope":[]},{"path":["str"],"name":"replace","title":"Replace","keywords":[],"oneliner":"Replace at most `count` occurrences of the given pattern with a replacement string or function (beginning from the start).","element":false,"contextual":false,"deprecationMessage":null,"deprecationUntil":null,"details":[{"kind":"html","content":"<p>Replace at most <code>count</code> occurrences of the given pattern with a\nreplacement string or function (beginning from the start). If no count\nis given, all occurrences are replaced.</p>"}],"self":true,"params":[{"name":"pattern","details":[{"kind":"html","content":"<p>The pattern to search for.</p>"}],"types":["str","regex"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false},{"name":"replacement","details":[{"kind":"html","content":"<p>The string to replace the matches with or a function that gets a\ndictionary for each match and can return individual replacement\nstrings.</p>\n<p>The dictionary passed to the function has the same shape as the\ndictionary returned by <a href=\"/en-US-v0.14.1/reference/foundations/str/#definitions-match\"><code>match</code></a>.</p>"}],"types":["str","function"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false},{"name":"count","details":[{"kind":"html","content":"<p>If given, only the first <code>count</code> matches of the pattern are placed.</p>"}],"types":["int"],"strings":[],"default":null,"positional":false,"named":true,"required":false,"variadic":false,"settable":false}],"returns":["str"],"scope":[]},{"path":["str"],"name":"trim","title":"Trim","keywords":[],"oneliner":"Removes matches of a pattern from one or both sides of the string, once or repeatedly and returns the resulting string.","element":false,"contextual":false,"deprecationMessage":null,"deprecationUntil":null,"details":[{"kind":"html","content":"<p>Removes matches of a pattern from one or both sides of the string, once or\nrepeatedly and returns the resulting string.</p>"}],"self":true,"params":[{"name":"pattern","details":[{"kind":"html","content":"<p>The pattern to search for. If <code><span class=\"typ-key\">none</span></code>, trims white spaces.</p>"}],"types":["none","str","regex"],"strings":[],"default":"<code><span class=\"typ-key\">none</span></code>","positional":true,"named":false,"required":false,"variadic":false,"settable":false},{"name":"at","details":[{"kind":"html","content":"<p>Can be <code>start</code> or <code>end</code> to only trim the start or end of the\nstring. If omitted, both sides are trimmed.</p>"}],"types":["alignment"],"strings":[],"default":null,"positional":false,"named":true,"required":false,"variadic":false,"settable":false},{"name":"repeat","details":[{"kind":"html","content":"<p>Whether to repeatedly removes matches of the pattern or just once.\nDefaults to <code><span class=\"typ-key\">true</span></code>.</p>"}],"types":["bool"],"strings":[],"default":"<code><span class=\"typ-key\">true</span></code>","positional":false,"named":true,"required":false,"variadic":false,"settable":false}],"returns":["str"],"scope":[]},{"path":["str"],"name":"split","title":"Split","keywords":[],"oneliner":"Splits a string at matches of a specified pattern and returns an array of the resulting parts.","element":false,"contextual":false,"deprecationMessage":null,"deprecationUntil":null,"details":[{"kind":"html","content":"<p>Splits a string at matches of a specified pattern and returns an array\nof the resulting parts.</p>\n<p>When the empty string is used as a separator, it separates every\ncharacter (i.e., Unicode code point) in the string, along with the\nbeginning and end of the string. In practice, this means that the\nresulting list of parts will contain the empty string at the start\nand end of the list.</p>"}],"self":true,"params":[{"name":"pattern","details":[{"kind":"html","content":"<p>The pattern to split at. Defaults to whitespace.</p>"}],"types":["none","str","regex"],"strings":[],"default":"<code><span class=\"typ-key\">none</span></code>","positional":true,"named":false,"required":false,"variadic":false,"settable":false}],"returns":["array"],"scope":[]},{"path":["str"],"name":"rev","title":"Reverse","keywords":[],"oneliner":"Reverse the string.","element":false,"contextual":false,"deprecationMessage":null,"deprecationUntil":null,"details":[{"kind":"html","content":"<p>Reverse the string.</p>"}],"self":true,"params":[],"returns":["str"],"scope":[]}]}}}