mirror of
https://github.com/nim-lang/Nim.git
synced 2026-05-28 15:55:14 +00:00
810 lines
98 KiB
HTML
810 lines
98 KiB
HTML
<?xml version="1.0" encoding="utf-8" ?>
|
||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||
<!-- This file is generated by Nim. -->
|
||
<html xmlns="https://www.w3.org/1999/xhtml" xml:lang="en" lang="en" data-theme="auto">
|
||
<head>
|
||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
<title>std/nre2</title>
|
||
|
||
<!-- Google fonts -->
|
||
<link href='https://fonts.googleapis.com/css?family=Lato:400,600,900' rel='stylesheet' type='text/css'/>
|
||
<link href='https://fonts.googleapis.com/css?family=Source+Code+Pro:400,500,600' rel='stylesheet' type='text/css'/>
|
||
|
||
<!-- Favicon -->
|
||
<link rel="shortcut icon" href="data:image/x-icon;base64,AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAUAAAAF////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAIAAABbAAAAlQAAAKIAAACbAAAAmwAAAKIAAACVAAAAWwAAAAL///8A////AP///wD///8A////AAAAABQAAADAAAAAYwAAAA3///8A////AP///wD///8AAAAADQAAAGMAAADAAAAAFP///wD///8A////AP///wAAAACdAAAAOv///wD///8A////AP///wD///8A////AP///wD///8AAAAAOgAAAJ3///8A////AP///wAAAAAnAAAAcP///wAAAAAoAAAASv///wD///8A////AP///wAAAABKAAAAKP///wAAAABwAAAAJ////wD///8AAAAAgQAAABwAAACIAAAAkAAAAJMAAACtAAAAFQAAABUAAACtAAAAkwAAAJAAAACIAAAAHAAAAIH///8A////AAAAAKQAAACrAAAAaP///wD///8AAAAARQAAANIAAADSAAAARf///wD///8AAAAAaAAAAKsAAACk////AAAAADMAAACcAAAAnQAAABj///8A////AP///wAAAAAYAAAAGP///wD///8A////AAAAABgAAACdAAAAnAAAADMAAAB1AAAAwwAAAP8AAADpAAAAsQAAAE4AAAAb////AP///wAAAAAbAAAATgAAALEAAADpAAAA/wAAAMMAAAB1AAAAtwAAAOkAAAD/AAAA/wAAAP8AAADvAAAA3gAAAN4AAADeAAAA3gAAAO8AAAD/AAAA/wAAAP8AAADpAAAAtwAAAGUAAAA/AAAA3wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAADfAAAAPwAAAGX///8A////AAAAAEgAAADtAAAAvwAAAL0AAADGAAAA7wAAAO8AAADGAAAAvQAAAL8AAADtAAAASP///wD///8A////AP///wD///8AAAAAO////wD///8A////AAAAAIcAAACH////AP///wD///8AAAAAO////wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A//8AAP//AAD4HwAA7/cAAN/7AAD//wAAoYUAAJ55AACf+QAAh+EAAAAAAADAAwAA4AcAAP5/AAD//wAA//8AAA=="/>
|
||
<link rel="icon" type="image/png" sizes="32x32" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAA3XAAAN1wFCKJt4AAAAB3RJTUUH4QQQEwksSS9ZWwAAAk1JREFUWMPtll2ITVEUx39nn/O7Y5qR8f05wtCUUr6ZIS++8pEnkZInPImneaCQ5METNdOkeFBKUhMPRIkHKfEuUZSUlGlKPN2TrgfncpvmnntnmlEyq1Z7t89/rf9a6+y99oZxGZf/XeIq61EdtgKXgdXA0xrYAvBjOIF1AI9zvjcC74BSpndrJPkBWDScTF8Aa4E3wDlgHbASaANmVqlcCnwHvgDvgVfAJ+AikAAvgfVZwLnSVZHZaOuKoQi3ZOMi4NkYkpe1p4J7A8BpYAD49hfIy/oqG0+hLomiKP2L5L+1ubn5115S+3OAn4EnwBlgMzCjyt6ZAnQCJ4A7wOs88iRJHvw50HoujuPBoCKwHWiosy8MdfZnAdcHk8dxXFJ3VQbQlCTJvRBCGdRbD4M6uc5glpY3eAihpN5S5w12diSEcCCEcKUO4ljdr15T76ur1FDDLIQQ3qv71EdDOe3Kxj3leRXyk+pxdWnFWod6Wt2bY3de3aSuUHcPBVimHs7mK9WrmeOF6lR1o9qnzskh2ar2qm1qizpfXaPeVGdlmGN5pb09qMxz1Xb1kLqgzn1RyH7JUXW52lr5e/Kqi9qpto7V1atuUzfnARrV7jEib1T76gG2qxdGmXyiekkt1GswPTtek0aBfJp6YySGBfWg2tPQ0FAYgf1stUfdmdcjarbYJEniKIq6gY/Aw+zWHAC+p2labGpqiorFYgGYCEzN7oQdQClN07O1/EfDyGgC0ALMBdYAi4FyK+4H3gLPsxfR1zRNi+NP7nH5J+QntnXe5B5mpfQAAAAASUVORK5CYII=">
|
||
|
||
<!-- CSS -->
|
||
<link rel="stylesheet" type="text/css" href="nimdoc.out.css?v=2.3.1">
|
||
|
||
<!-- JS -->
|
||
<script type="text/javascript" src="dochack.js?v=2.3.1"></script>
|
||
</head>
|
||
<body>
|
||
<div class="document" id="documentId">
|
||
<input type="checkbox" id="nav-toggle" hidden>
|
||
<label for="nav-toggle" id="nav-burger">☰</label>
|
||
<label for="nav-toggle" id="nav-overlay"></label>
|
||
<div class="container">
|
||
<h1 class="title">std/nre2</h1>
|
||
<div class="row">
|
||
<div class="three columns">
|
||
<div class="theme-select-wrapper">
|
||
<label for="theme-select">Theme: </label>
|
||
<select id="theme-select" onchange="setTheme(this.value)">
|
||
<option value="auto">🌗 Match OS</option>
|
||
<option value="dark">🌑 Dark</option>
|
||
<option value="light">🌕 Light</option>
|
||
</select>
|
||
</div>
|
||
<div id="global-links">
|
||
<ul class="simple-boot">
|
||
<li><a href="manual.html">Manual</a></li>
|
||
<li><a href="lib.html">Standard library</a></li>
|
||
<li> <a id="indexLink" href="theindex.html">Index</a></li>
|
||
<li><a href="compiler/theindex.html">Compiler docs</a></li>
|
||
<li><a href="https://nim-lang.github.io/fusion/theindex.html">Fusion docs</a></li>
|
||
<li><a href="https://nim-lang.github.io/Nim/">devel</a>, <a href="https://nim-lang.org/documentation.html">stable</a></li>
|
||
</ul>
|
||
</div>
|
||
<div id="searchInputDiv">
|
||
Search: <input type="search" id="searchInput"
|
||
oninput="search()" />
|
||
</div>
|
||
|
||
<ul class="simple simple-toc" id="toc-list">
|
||
<li><a class="reference" id="what-is-nre2qmark_toc" href="#what-is-nre2qmark">What is NRE2?</a></li>
|
||
<li>
|
||
<a class="reference reference-toplevel" href="#6" id="56">Imports</a>
|
||
</li>
|
||
<li>
|
||
<details open>
|
||
<summary><a class="reference reference-toplevel" href="#7" id="57">Types</a></summary>
|
||
<ul class="simple simple-toc-section">
|
||
<li><a class="reference" href="#CaptureBounds" title="CaptureBounds {.borrow: `.`.} = distinct RegexMatch">CaptureBounds</a></li>
|
||
<li><a class="reference" href="#Captures" title="Captures {.borrow: `.`.} = distinct RegexMatch">Captures</a></li>
|
||
<li><a class="reference" href="#Regex" title="Regex = regex.Regex2">Regex</a></li>
|
||
<li><a class="reference" href="#RegexMatch" title="RegexMatch = object
|
||
str*: string ## The string that was matched against.">RegexMatch</a></li>
|
||
|
||
</ul>
|
||
</details>
|
||
</li>
|
||
<li>
|
||
<details open>
|
||
<summary><a class="reference reference-toplevel" href="#12" id="62">Procs</a></summary>
|
||
<ul class="simple simple-toc-section">
|
||
<ul class="simple nested-toc-section">$
|
||
<li><a class="reference" href="#%24%2CRegexMatch" title="`$`(match: RegexMatch): string">`$`(match: RegexMatch): string</a></li>
|
||
|
||
</ul>
|
||
<ul class="simple nested-toc-section">[]
|
||
<li><a class="reference" href="#%5B%5D%2CCaptureBounds%2Cint" title="`[]`(match: CaptureBounds; i: int): HSlice[int, int]">`[]`(match: CaptureBounds; i: int): HSlice[int, int]</a></li>
|
||
<li><a class="reference" href="#%5B%5D%2CCaptureBounds%2Cstring" title="`[]`(match: CaptureBounds; name: string): HSlice[int, int]">`[]`(match: CaptureBounds; name: string): HSlice[int, int]</a></li>
|
||
<li><a class="reference" href="#%5B%5D%2CCaptures%2Cint" title="`[]`(match: Captures; i: int): string">`[]`(match: Captures; i: int): string</a></li>
|
||
<li><a class="reference" href="#%5B%5D%2CCaptures%2Cstring" title="`[]`(match: Captures; name: string): string">`[]`(match: Captures; name: string): string</a></li>
|
||
|
||
</ul>
|
||
<ul class="simple nested-toc-section">captureBounds
|
||
<li><a class="reference" href="#captureBounds%2CRegexMatch" title="captureBounds(match: RegexMatch): CaptureBounds">captureBounds(match: RegexMatch): CaptureBounds</a></li>
|
||
|
||
</ul>
|
||
<ul class="simple nested-toc-section">captureCount
|
||
<li><a class="reference" href="#captureCount%2CRegex2" title="captureCount(pattern: Regex): int">captureCount(pattern: Regex): int</a></li>
|
||
|
||
</ul>
|
||
<ul class="simple nested-toc-section">captureNameId
|
||
<li><a class="reference" href="#captureNameId%2CRegex2" title="captureNameId(pattern: Regex): Table[string, int]">captureNameId(pattern: Regex): Table[string, int]</a></li>
|
||
|
||
</ul>
|
||
<ul class="simple nested-toc-section">captures
|
||
<li><a class="reference" href="#captures%2CRegexMatch" title="captures(match: RegexMatch): Captures">captures(match: RegexMatch): Captures</a></li>
|
||
|
||
</ul>
|
||
<ul class="simple nested-toc-section">contains
|
||
<li><a class="reference" href="#contains%2C%2Cstring" title="contains(match: CaptureBounds or Captures; name: string): bool">contains(match: CaptureBounds or Captures; name: string): bool</a></li>
|
||
<li><a class="reference" href="#contains%2C%2Cint" title="contains(match: Captures or CaptureBounds; i: int): bool">contains(match: Captures or CaptureBounds; i: int): bool</a></li>
|
||
<li><a class="reference" href="#contains%2Cstring%2CRegex2%2Cint" title="contains(str: string; pattern: Regex; start = 0; endpos = int.high): bool">contains(str: string; pattern: Regex; start = 0; endpos = int.high): bool</a></li>
|
||
|
||
</ul>
|
||
<ul class="simple nested-toc-section">escapeRe
|
||
<li><a class="reference" href="#escapeRe%2Cstring" title="escapeRe(str: string): string">escapeRe(str: string): string</a></li>
|
||
|
||
</ul>
|
||
<ul class="simple nested-toc-section">find
|
||
<li><a class="reference" href="#find%2Cstring%2CRegex2%2Cint" title="find(str: string; pattern: Regex; start = 0; endpos = int.high): Option[
|
||
RegexMatch]">find(str: string; pattern: Regex; start = 0; endpos = int.high): Option[
|
||
RegexMatch]</a></li>
|
||
|
||
</ul>
|
||
<ul class="simple nested-toc-section">findAll
|
||
<li><a class="reference" href="#findAll%2Cstring%2CRegex2%2Cint" title="findAll(str: string; pattern: Regex; start = 0; endpos = int.high): seq[string]">findAll(str: string; pattern: Regex; start = 0; endpos = int.high): seq[string]</a></li>
|
||
|
||
</ul>
|
||
<ul class="simple nested-toc-section">len
|
||
<li><a class="reference" href="#len" title="len(match: Captures or CaptureBounds): int">len(match: Captures or CaptureBounds): int</a></li>
|
||
|
||
</ul>
|
||
<ul class="simple nested-toc-section">match
|
||
<li><a class="reference" href="#match%2CRegexMatch" title="match(match: RegexMatch): string">match(match: RegexMatch): string</a></li>
|
||
<li><a class="reference" href="#match%2Cstring%2CRegex2%2Cint" title="match(str: string; pattern: Regex; start = 0; endpos = int.high): Option[
|
||
RegexMatch]">match(str: string; pattern: Regex; start = 0; endpos = int.high): Option[
|
||
RegexMatch]</a></li>
|
||
|
||
</ul>
|
||
<ul class="simple nested-toc-section">matchBounds
|
||
<li><a class="reference" href="#matchBounds%2CRegexMatch" title="matchBounds(match: RegexMatch): HSlice[int, int]">matchBounds(match: RegexMatch): HSlice[int, int]</a></li>
|
||
|
||
</ul>
|
||
<ul class="simple nested-toc-section">re
|
||
<li><a class="reference" href="#re%2Cstaticstring%2CstaticRegexFlags" title="re(pattern: static string; flags: static RegexFlags = {}): static[Regex2]">re(pattern: static string; flags: static RegexFlags = {}): static[Regex2]</a></li>
|
||
<li><a class="reference" href="#re%2Cstring%2CRegexFlags" title="re(pattern: string; flags: RegexFlags = {}): Regex">re(pattern: string; flags: RegexFlags = {}): Regex</a></li>
|
||
|
||
</ul>
|
||
<ul class="simple nested-toc-section">replace
|
||
<li><a class="reference" href="#replace%2Cstring%2CRegex2%2Cstring" title="replace(str: string; pattern: Regex; sub: string): string">replace(str: string; pattern: Regex; sub: string): string</a></li>
|
||
<li><a class="reference" href="#replace%2Cstring%2CRegex2%2Cproc%28RegexMatch%29" title="replace(str: string; pattern: Regex; subproc: proc (match: RegexMatch): string): string">replace(str: string; pattern: Regex; subproc: proc (match: RegexMatch): string): string</a></li>
|
||
<li><a class="reference" href="#replace%2Cstring%2CRegex2%2Cproc%28string%29" title="replace(str: string; pattern: Regex; subproc: proc (match: string): string): string">replace(str: string; pattern: Regex; subproc: proc (match: string): string): string</a></li>
|
||
|
||
</ul>
|
||
<ul class="simple nested-toc-section">split
|
||
<li><a class="reference" href="#split%2Cstring%2CRegex2%2Cint%2Cint" title="split(str: string; pattern: Regex; maxSplit = -1; start = 0): seq[string]">split(str: string; pattern: Regex; maxSplit = -1; start = 0): seq[string]</a></li>
|
||
|
||
</ul>
|
||
<ul class="simple nested-toc-section">toSeq
|
||
<li><a class="reference" href="#toSeq%2CCaptureBounds" title="toSeq(match: CaptureBounds; default = none(HSlice[int, int])): seq[
|
||
Option[HSlice[int, int]]]">toSeq(match: CaptureBounds; default = none(HSlice[int, int])): seq[
|
||
Option[HSlice[int, int]]]</a></li>
|
||
<li><a class="reference" href="#toSeq%2CCaptures%2COption%5Bstring%5D" title="toSeq(match: Captures; default: Option[string] = none(string)): seq[
|
||
Option[string]]">toSeq(match: Captures; default: Option[string] = none(string)): seq[
|
||
Option[string]]</a></li>
|
||
|
||
</ul>
|
||
<ul class="simple nested-toc-section">toTable
|
||
<li><a class="reference" href="#toTable%2CCaptureBounds" title="toTable(match: CaptureBounds): Table[string, HSlice[int, int]]">toTable(match: CaptureBounds): Table[string, HSlice[int, int]]</a></li>
|
||
<li><a class="reference" href="#toTable%2CCaptures" title="toTable(match: Captures): Table[string, string]">toTable(match: Captures): Table[string, string]</a></li>
|
||
|
||
</ul>
|
||
|
||
</ul>
|
||
</details>
|
||
</li>
|
||
<li>
|
||
<details open>
|
||
<summary><a class="reference reference-toplevel" href="#15" id="65">Iterators</a></summary>
|
||
<ul class="simple simple-toc-section">
|
||
<ul class="simple nested-toc-section">findIter
|
||
<li><a class="reference" href="#findIter.i%2Cstring%2CRegex2%2Cint" title="findIter(str: string; pattern: Regex; start = 0; endpos = int.high): RegexMatch">findIter(str: string; pattern: Regex; start = 0; endpos = int.high): RegexMatch</a></li>
|
||
|
||
</ul>
|
||
<ul class="simple nested-toc-section">items
|
||
<li><a class="reference" href="#items.i%2CCaptureBounds" title="items(match: CaptureBounds; default = none(HSlice[int, int])): Option[
|
||
HSlice[int, int]]">items(match: CaptureBounds; default = none(HSlice[int, int])): Option[
|
||
HSlice[int, int]]</a></li>
|
||
<li><a class="reference" href="#items.i%2CCaptures" title="items(match: Captures; default = none(string)): Option[string]">items(match: Captures; default = none(string)): Option[string]</a></li>
|
||
|
||
</ul>
|
||
|
||
</ul>
|
||
</details>
|
||
</li>
|
||
<li>
|
||
<a class="reference reference-toplevel" href="#19" id="69">Exports</a>
|
||
</li>
|
||
|
||
</ul>
|
||
|
||
</div>
|
||
<div class="nine columns" id="content">
|
||
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/nre2.nim#L1" class="link-seesrc" target="_blank">Source</a>
|
||
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/nre2.nim#L1" class="link-seesrc" target="_blank" >Edit</a>
|
||
|
||
<div id="tocRoot"></div>
|
||
|
||
<p class="module-desc">
|
||
<h1><a class="toc-backref" id="what-is-nre2qmark" href="#what-is-nre2qmark">What is NRE2?</a></h1><p>A regular expression library for Nim to replace deprecated NRE. It is implemented with <a class="reference external" href="https://github.com/nitely/nim-regex">Regex</a> , that is pure Nim regex engine and guarantees linear time matching. It supports compiling regex and matching at compile-time and works with JS backend.</p>
|
||
<p>NRE2 is mostly compatible with NRE and the syntax of regular expression is similar to PCRE. But it lacks a few features and how to set options in a pattern is different.</p>
|
||
<p>The syntax of regular expression is explained in <a class="reference external" href="https://nitely.github.io/nim-regex/regex.html">https://nitely.github.io/nim-regex/regex.html</a></p>
|
||
|
||
<p><strong class="examples_text">Example:</strong></p>
|
||
<pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">nre2</span>
|
||
<span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">sugar</span>
|
||
<span class="Keyword">let</span> <span class="Identifier">vowels</span> <span class="Operator">=</span> <span class="RawData">re"[aeoui]"</span>
|
||
<span class="Keyword">let</span> <span class="Identifier">bounds</span> <span class="Operator">=</span> <span class="Identifier">collect</span><span class="Punctuation">:</span>
|
||
<span class="Keyword">for</span> <span class="Identifier">match</span> <span class="Keyword">in</span> <span class="StringLit">"moiga"</span><span class="Operator">.</span><span class="Identifier">findIter</span><span class="Punctuation">(</span><span class="Identifier">vowels</span><span class="Punctuation">)</span><span class="Punctuation">:</span> <span class="Identifier">match</span><span class="Operator">.</span><span class="Identifier">matchBounds</span>
|
||
<span class="Identifier">assert</span> <span class="Identifier">bounds</span> <span class="Operator">==</span> <span class="Operator">@</span><span class="Punctuation">[</span><span class="DecNumber">1</span> <span class="Operator">..</span> <span class="DecNumber">1</span><span class="Punctuation">,</span> <span class="DecNumber">2</span> <span class="Operator">..</span> <span class="DecNumber">2</span><span class="Punctuation">,</span> <span class="DecNumber">4</span> <span class="Operator">..</span> <span class="DecNumber">4</span><span class="Punctuation">]</span>
|
||
<span class="Keyword">from</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">sequtils</span> <span class="Keyword">import</span> <span class="Identifier">toSeq</span>
|
||
<span class="Keyword">let</span> <span class="Identifier">s</span> <span class="Operator">=</span> <span class="Identifier">sequtils</span><span class="Operator">.</span><span class="Identifier">toSeq</span><span class="Punctuation">(</span><span class="StringLit">"moiga"</span><span class="Operator">.</span><span class="Identifier">findIter</span><span class="Punctuation">(</span><span class="Identifier">vowels</span><span class="Punctuation">)</span><span class="Punctuation">)</span>
|
||
<span class="Comment"># fully qualified to avoid confusion with nre.toSeq</span>
|
||
<span class="Identifier">assert</span> <span class="Identifier">s</span><span class="Operator">.</span><span class="Identifier">len</span> <span class="Operator">==</span> <span class="DecNumber">3</span>
|
||
|
||
<span class="Keyword">let</span> <span class="Identifier">firstVowel</span> <span class="Operator">=</span> <span class="StringLit">"foo"</span><span class="Operator">.</span><span class="Identifier">find</span><span class="Punctuation">(</span><span class="Identifier">vowels</span><span class="Punctuation">)</span>
|
||
<span class="Keyword">let</span> <span class="Identifier">hasVowel</span> <span class="Operator">=</span> <span class="Identifier">firstVowel</span><span class="Operator">.</span><span class="Identifier">isSome</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
|
||
<span class="Identifier">assert</span> <span class="Identifier">hasVowel</span>
|
||
<span class="Keyword">let</span> <span class="Identifier">matchBounds</span> <span class="Operator">=</span> <span class="Identifier">firstVowel</span><span class="Operator">.</span><span class="Identifier">get</span><span class="Punctuation">(</span><span class="Punctuation">)</span><span class="Operator">.</span><span class="Identifier">captureBounds</span><span class="Punctuation">[</span><span class="Operator">-</span><span class="DecNumber">1</span><span class="Punctuation">]</span>
|
||
<span class="Identifier">assert</span> <span class="Identifier">matchBounds</span><span class="Operator">.</span><span class="Identifier">a</span> <span class="Operator">==</span> <span class="DecNumber">1</span>
|
||
|
||
<span class="Comment"># as with module `re`, unless specified otherwise, `start` parameter in each</span>
|
||
<span class="Comment"># proc indicates where the scan starts, but outputs are relative to the start</span>
|
||
<span class="Comment"># of the input string, not to `start`:</span>
|
||
<span class="Identifier">assert</span> <span class="Identifier">find</span><span class="Punctuation">(</span><span class="StringLit">"uxabc"</span><span class="Punctuation">,</span> <span class="RawData">re"(?<=x|y)ab"</span><span class="Punctuation">,</span> <span class="Identifier">start</span> <span class="Operator">=</span> <span class="DecNumber">1</span><span class="Punctuation">)</span><span class="Operator">.</span><span class="Identifier">get</span><span class="Operator">.</span><span class="Identifier">captures</span><span class="Punctuation">[</span><span class="Operator">-</span><span class="DecNumber">1</span><span class="Punctuation">]</span> <span class="Operator">==</span> <span class="StringLit">"ab"</span>
|
||
<span class="Identifier">assert</span> <span class="Identifier">find</span><span class="Punctuation">(</span><span class="StringLit">"uxabc"</span><span class="Punctuation">,</span> <span class="RawData">re"ab"</span><span class="Punctuation">,</span> <span class="Identifier">start</span> <span class="Operator">=</span> <span class="DecNumber">3</span><span class="Punctuation">)</span><span class="Operator">.</span><span class="Identifier">isNone</span></pre></p>
|
||
<div class="section" id="6">
|
||
<h1><a class="toc-backref" href="#6">Imports</a></h1>
|
||
<dl class="item">
|
||
<a class="reference external" href="options.html">options</a>, <a class="reference external" href="tables.html">tables</a>
|
||
</dl>
|
||
</div>
|
||
<div class="section" id="7">
|
||
<h1><a class="toc-backref" href="#7">Types</a></h1>
|
||
<dl class="item">
|
||
<div id="CaptureBounds">
|
||
<dt><pre><a href="#CaptureBounds"><span class="Identifier">CaptureBounds</span></a> {.<span class="Identifier">borrow</span><span class="Other">:</span> <span class="Other">`</span><span class="Operator">.</span><span class="Other">`</span>.} <span class="Other">=</span> <span class="Keyword">distinct</span> <a href="#RegexMatch"><span class="Identifier">RegexMatch</span></a></pre></dt>
|
||
<dd>
|
||
|
||
|
||
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/nre2.nim#L100" class="link-seesrc" target="_blank">Source</a>
|
||
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/nre2.nim#L100" class="link-seesrc" target="_blank" >Edit</a>
|
||
|
||
</dd>
|
||
</div>
|
||
<div id="Captures">
|
||
<dt><pre><a href="#Captures"><span class="Identifier">Captures</span></a> {.<span class="Identifier">borrow</span><span class="Other">:</span> <span class="Other">`</span><span class="Operator">.</span><span class="Other">`</span>.} <span class="Other">=</span> <span class="Keyword">distinct</span> <a href="#RegexMatch"><span class="Identifier">RegexMatch</span></a></pre></dt>
|
||
<dd>
|
||
|
||
|
||
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/nre2.nim#L99" class="link-seesrc" target="_blank">Source</a>
|
||
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/nre2.nim#L99" class="link-seesrc" target="_blank" >Edit</a>
|
||
|
||
</dd>
|
||
</div>
|
||
<div id="Regex">
|
||
<dt><pre><a href="#Regex"><span class="Identifier">Regex</span></a> <span class="Other">=</span> <span class="Identifier">regex</span><span class="Other">.</span><span class="Identifier">Regex2</span></pre></dt>
|
||
<dd>
|
||
|
||
Represents the pattern that things are matched against, constructed with <tt class="docutils literal"><span class="pre"><span class="Identifier">re</span><span class="Punctuation">(</span><span class="Identifier">string</span><span class="Punctuation">)</span></span></tt>. Examples: <tt class="docutils literal"><span class="pre"><span class="RawData">re"foo"</span></span></tt>, <tt class="docutils literal"><span class="pre"><span class="Identifier">re</span><span class="Punctuation">(</span><span class="RawData">r"(?x)foo #comment"</span><span class="Punctuation">)</span></span></tt><dl class="docutils"><dt><tt class="docutils literal"><span class="pre"><span class="Identifier">captureCount</span><span class="Punctuation">:</span> <span class="Identifier">int</span></span></tt></dt>
|
||
<dd>the number of captures that the pattern has.</dd>
|
||
<dt><tt class="docutils literal"><span class="pre"><span class="Identifier">captureNameId</span><span class="Punctuation">:</span> <span class="Identifier">Table</span><span class="Punctuation">[</span><span class="Identifier">string</span><span class="Punctuation">,</span> <span class="Identifier">int</span><span class="Punctuation">]</span></span></tt></dt>
|
||
<dd>a table from the capture names to their numeric id.</dd>
|
||
</dl>
|
||
<p>The syntax of regular expression of Regex is explained in <a class="reference external" href="https://nitely.github.io/nim-regex/regex.html">https://nitely.github.io/nim-regex/regex.html</a></p>
|
||
|
||
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/nre2.nim#L52" class="link-seesrc" target="_blank">Source</a>
|
||
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/nre2.nim#L52" class="link-seesrc" target="_blank" >Edit</a>
|
||
|
||
</dd>
|
||
</div>
|
||
<div id="RegexMatch">
|
||
<dt><pre><a href="#RegexMatch"><span class="Identifier">RegexMatch</span></a> <span class="Other">=</span> <span class="Keyword">object</span>
|
||
<span class="Identifier">str</span><span class="Operator">*</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> <span class="Comment">## The string that was matched against.</span></pre></dt>
|
||
<dd>
|
||
|
||
Usually seen as <tt class="docutils literal"><span class="pre"><span class="Identifier">Option</span><span class="Punctuation">[</span><span class="Identifier">RegexMatch</span><span class="Punctuation">]</span></span></tt>, it represents the result of an execution. On failure, it is none, on success, it is some.<dl class="docutils"><dt><tt class="docutils literal"><span class="pre"><span class="Identifier">str</span><span class="Punctuation">:</span> <span class="Identifier">string</span></span></tt></dt>
|
||
<dd>the string that was matched against</dd>
|
||
<dt><tt class="docutils literal"><span class="pre"><span class="Identifier">captures</span><span class="Punctuation">[</span><span class="Punctuation">]</span><span class="Punctuation">:</span> <span class="Identifier">string</span></span></tt></dt>
|
||
<dd>the string value of whatever was captured at that id. If the value is invalid, then behavior is undefined. If the id is <tt class="docutils literal"><span class="pre"><span class="Operator">-</span><span class="DecNumber">1</span></span></tt>, then the whole match is returned. If the given capture was not matched, <tt class="docutils literal"><span class="pre"><span class="Keyword">nil</span></span></tt> is returned. See examples for <tt class="docutils literal"><span class="pre"><span class="Identifier">match</span></span></tt>.</dd>
|
||
<dt><tt class="docutils literal"><span class="pre"><span class="Identifier">captureBounds</span><span class="Punctuation">[</span><span class="Punctuation">]</span><span class="Punctuation">:</span> <span class="Identifier">HSlice</span><span class="Punctuation">[</span><span class="Identifier">int</span><span class="Punctuation">,</span> <span class="Identifier">int</span><span class="Punctuation">]</span></span></tt></dt>
|
||
<dd>gets the bounds of the given capture according to the same rules as the above. If the capture is not filled, then <tt class="docutils literal"><span class="pre"><span class="Identifier">None</span></span></tt> is returned. The bounds are both inclusive. See examples for <tt class="docutils literal"><span class="pre"><span class="Identifier">match</span></span></tt>.</dd>
|
||
<dt><tt class="docutils literal"><span class="pre"><span class="Identifier">match</span><span class="Punctuation">:</span> <span class="Identifier">string</span></span></tt></dt>
|
||
<dd>the full text of the match.</dd>
|
||
<dt><tt class="docutils literal"><span class="pre"><span class="Identifier">matchBounds</span><span class="Punctuation">:</span> <span class="Identifier">HSlice</span><span class="Punctuation">[</span><span class="Identifier">int</span><span class="Punctuation">,</span> <span class="Identifier">int</span><span class="Punctuation">]</span></span></tt></dt>
|
||
<dd>the bounds of the match, as in <tt class="docutils literal"><span class="pre"><span class="Identifier">captureBounds</span><span class="Punctuation">[</span><span class="Punctuation">]</span></span></tt></dd>
|
||
<dt><tt class="docutils literal"><span class="pre"><span class="Punctuation">(</span><span class="Identifier">captureBounds</span><span class="Operator">|</span><span class="Identifier">captures</span><span class="Punctuation">)</span><span class="Operator">.</span><span class="Identifier">toTable</span></span></tt></dt>
|
||
<dd>returns a table with each named capture as a key.</dd>
|
||
<dt><tt class="docutils literal"><span class="pre"><span class="Punctuation">(</span><span class="Identifier">captureBounds</span><span class="Operator">|</span><span class="Identifier">captures</span><span class="Punctuation">)</span><span class="Operator">.</span><span class="Identifier">toSeq</span></span></tt></dt>
|
||
<dd>returns all the captures by their number.</dd>
|
||
<dt><tt class="docutils literal"><span class="pre"><span class="Operator">$:</span> <span class="Identifier">string</span></span></tt></dt>
|
||
<dd>same as <tt class="docutils literal"><span class="pre"><span class="Identifier">match</span></span></tt></dd>
|
||
</dl>
|
||
|
||
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/nre2.nim#L64" class="link-seesrc" target="_blank">Source</a>
|
||
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/nre2.nim#L64" class="link-seesrc" target="_blank" >Edit</a>
|
||
|
||
</dd>
|
||
</div>
|
||
|
||
</dl>
|
||
</div>
|
||
<div class="section" id="12">
|
||
<h1><a class="toc-backref" href="#12">Procs</a></h1>
|
||
<dl class="item">
|
||
<div id="$-procs-all">
|
||
<div id="$,RegexMatch">
|
||
<dt><pre><span class="Keyword">func</span> <a href="#%24%2CRegexMatch"><span class="Identifier">`$`</span></a><span class="Other">(</span><span class="Identifier">match</span><span class="Other">:</span> <a href="#RegexMatch"><span class="Identifier">RegexMatch</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||
<dd>
|
||
|
||
|
||
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/nre2.nim#L179" class="link-seesrc" target="_blank">Source</a>
|
||
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/nre2.nim#L179" class="link-seesrc" target="_blank" >Edit</a>
|
||
|
||
</dd>
|
||
</div>
|
||
|
||
</div>
|
||
<div id="[]-procs-all">
|
||
<div id="[],CaptureBounds,int">
|
||
<dt><pre><span class="Keyword">func</span> <a href="#%5B%5D%2CCaptureBounds%2Cint"><span class="Identifier">`[]`</span></a><span class="Other">(</span><span class="Identifier">match</span><span class="Other">:</span> <a href="#CaptureBounds"><span class="Identifier">CaptureBounds</span></a><span class="Other">;</span> <span class="Identifier">i</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#HSlice"><span class="Identifier">HSlice</span></a><span class="Other">[</span><a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">,</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">]</span> {.<span class="Identifier">inline</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
|
||
<span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||
<dd>
|
||
|
||
|
||
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/nre2.nim#L123" class="link-seesrc" target="_blank">Source</a>
|
||
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/nre2.nim#L123" class="link-seesrc" target="_blank" >Edit</a>
|
||
|
||
</dd>
|
||
</div>
|
||
<div id="[],CaptureBounds,string">
|
||
<dt><pre><span class="Keyword">func</span> <a href="#%5B%5D%2CCaptureBounds%2Cstring"><span class="Identifier">`[]`</span></a><span class="Other">(</span><span class="Identifier">match</span><span class="Other">:</span> <a href="#CaptureBounds"><span class="Identifier">CaptureBounds</span></a><span class="Other">;</span> <span class="Identifier">name</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#HSlice"><span class="Identifier">HSlice</span></a><span class="Other">[</span><a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">,</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">]</span> {.<span class="Identifier">inline</span><span class="Other">,</span>
|
||
<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">KeyError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||
<dd>
|
||
|
||
|
||
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/nre2.nim#L126" class="link-seesrc" target="_blank">Source</a>
|
||
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/nre2.nim#L126" class="link-seesrc" target="_blank" >Edit</a>
|
||
|
||
</dd>
|
||
</div>
|
||
<div id="[],Captures,int">
|
||
<dt><pre><span class="Keyword">func</span> <a href="#%5B%5D%2CCaptures%2Cint"><span class="Identifier">`[]`</span></a><span class="Other">(</span><span class="Identifier">match</span><span class="Other">:</span> <a href="#Captures"><span class="Identifier">Captures</span></a><span class="Other">;</span> <span class="Identifier">i</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> {.<span class="Identifier">inline</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
|
||
<span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||
<dd>
|
||
|
||
|
||
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/nre2.nim#L131" class="link-seesrc" target="_blank">Source</a>
|
||
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/nre2.nim#L131" class="link-seesrc" target="_blank" >Edit</a>
|
||
|
||
</dd>
|
||
</div>
|
||
<div id="[],Captures,string">
|
||
<dt><pre><span class="Keyword">func</span> <a href="#%5B%5D%2CCaptures%2Cstring"><span class="Identifier">`[]`</span></a><span class="Other">(</span><span class="Identifier">match</span><span class="Other">:</span> <a href="#Captures"><span class="Identifier">Captures</span></a><span class="Other">;</span> <span class="Identifier">name</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> {.<span class="Identifier">inline</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">KeyError</span><span class="Other">]</span><span class="Other">,</span>
|
||
<span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||
<dd>
|
||
|
||
|
||
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/nre2.nim#L134" class="link-seesrc" target="_blank">Source</a>
|
||
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/nre2.nim#L134" class="link-seesrc" target="_blank" >Edit</a>
|
||
|
||
</dd>
|
||
</div>
|
||
|
||
</div>
|
||
<div id="captureBounds-procs-all">
|
||
<div id="captureBounds,RegexMatch">
|
||
<dt><pre><span class="Keyword">func</span> <a href="#captureBounds%2CRegexMatch"><span class="Identifier">captureBounds</span></a><span class="Other">(</span><span class="Identifier">match</span><span class="Other">:</span> <a href="#RegexMatch"><span class="Identifier">RegexMatch</span></a><span class="Other">)</span><span class="Other">:</span> <a href="#CaptureBounds"><span class="Identifier">CaptureBounds</span></a> {.<span class="Identifier">inline</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
|
||
<span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||
<dd>
|
||
|
||
|
||
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/nre2.nim#L110" class="link-seesrc" target="_blank">Source</a>
|
||
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/nre2.nim#L110" class="link-seesrc" target="_blank" >Edit</a>
|
||
|
||
</dd>
|
||
</div>
|
||
|
||
</div>
|
||
<div id="captureCount-procs-all">
|
||
<div id="captureCount,Regex2">
|
||
<dt><pre><span class="Keyword">func</span> <a href="#captureCount%2CRegex2"><span class="Identifier">captureCount</span></a><span class="Other">(</span><span class="Identifier">pattern</span><span class="Other">:</span> <a href="#Regex"><span class="Identifier">Regex</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.<span class="Identifier">inline</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
|
||
<span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||
<dd>
|
||
|
||
|
||
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/nre2.nim#L102" class="link-seesrc" target="_blank">Source</a>
|
||
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/nre2.nim#L102" class="link-seesrc" target="_blank" >Edit</a>
|
||
|
||
</dd>
|
||
</div>
|
||
|
||
</div>
|
||
<div id="captureNameId-procs-all">
|
||
<div id="captureNameId,Regex2">
|
||
<dt><pre><span class="Keyword">func</span> <a href="#captureNameId%2CRegex2"><span class="Identifier">captureNameId</span></a><span class="Other">(</span><span class="Identifier">pattern</span><span class="Other">:</span> <a href="#Regex"><span class="Identifier">Regex</span></a><span class="Other">)</span><span class="Other">:</span> <a href="tables.html#Table"><span class="Identifier">Table</span></a><span class="Other">[</span><a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">,</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">]</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
|
||
<span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||
<dd>
|
||
|
||
|
||
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/nre2.nim#L105" class="link-seesrc" target="_blank">Source</a>
|
||
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/nre2.nim#L105" class="link-seesrc" target="_blank" >Edit</a>
|
||
|
||
</dd>
|
||
</div>
|
||
|
||
</div>
|
||
<div id="captures-procs-all">
|
||
<div id="captures,RegexMatch">
|
||
<dt><pre><span class="Keyword">func</span> <a href="#captures%2CRegexMatch"><span class="Identifier">captures</span></a><span class="Other">(</span><span class="Identifier">match</span><span class="Other">:</span> <a href="#RegexMatch"><span class="Identifier">RegexMatch</span></a><span class="Other">)</span><span class="Other">:</span> <a href="#Captures"><span class="Identifier">Captures</span></a> {.<span class="Identifier">inline</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
|
||
<span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||
<dd>
|
||
|
||
|
||
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/nre2.nim#L113" class="link-seesrc" target="_blank">Source</a>
|
||
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/nre2.nim#L113" class="link-seesrc" target="_blank" >Edit</a>
|
||
|
||
</dd>
|
||
</div>
|
||
|
||
</div>
|
||
<div id="contains-procs-all">
|
||
<div id="contains,,string">
|
||
<dt><pre><span class="Keyword">func</span> <a href="#contains%2C%2Cstring"><span class="Identifier">contains</span></a><span class="Other">(</span><span class="Identifier">match</span><span class="Other">:</span> <a href="#CaptureBounds"><span class="Identifier">CaptureBounds</span></a> <span class="Keyword">or</span> <a href="#Captures"><span class="Identifier">Captures</span></a><span class="Other">;</span> <span class="Identifier">name</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a> {.<span class="Identifier">inline</span>.}</pre></dt>
|
||
<dd>
|
||
|
||
|
||
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/nre2.nim#L143" class="link-seesrc" target="_blank">Source</a>
|
||
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/nre2.nim#L143" class="link-seesrc" target="_blank" >Edit</a>
|
||
|
||
</dd>
|
||
</div>
|
||
<div id="contains,,int">
|
||
<dt><pre><span class="Keyword">func</span> <a href="#contains%2C%2Cint"><span class="Identifier">contains</span></a><span class="Other">(</span><span class="Identifier">match</span><span class="Other">:</span> <a href="#Captures"><span class="Identifier">Captures</span></a> <span class="Keyword">or</span> <a href="#CaptureBounds"><span class="Identifier">CaptureBounds</span></a><span class="Other">;</span> <span class="Identifier">i</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a> {.<span class="Identifier">inline</span>.}</pre></dt>
|
||
<dd>
|
||
|
||
|
||
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/nre2.nim#L116" class="link-seesrc" target="_blank">Source</a>
|
||
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/nre2.nim#L116" class="link-seesrc" target="_blank" >Edit</a>
|
||
|
||
</dd>
|
||
</div>
|
||
<div id="contains,string,Regex2,int">
|
||
<dt><pre><span class="Keyword">proc</span> <a href="#contains%2Cstring%2CRegex2%2Cint"><span class="Identifier">contains</span></a><span class="Other">(</span><span class="Identifier">str</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">pattern</span><span class="Other">:</span> <a href="#Regex"><span class="Identifier">Regex</span></a><span class="Other">;</span> <span class="Identifier">start</span> <span class="Other">=</span> <span class="DecNumber">0</span><span class="Other">;</span> <span class="Identifier">endpos</span> <span class="Other">=</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">.</span><span class="Identifier">high</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a> {.
|
||
<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||
<dd>
|
||
|
||
Determine if the string contains the given pattern between the end and start positions: This function is equivalent to <tt class="docutils literal"><span class="pre"><span class="Identifier">isSome</span><span class="Punctuation">(</span><span class="Identifier">str</span><span class="Operator">.</span><span class="Identifier">find</span><span class="Punctuation">(</span><span class="Identifier">pattern</span><span class="Punctuation">,</span> <span class="Identifier">start</span><span class="Punctuation">,</span> <span class="Identifier">endpos</span><span class="Punctuation">)</span><span class="Punctuation">)</span></span></tt>.
|
||
<p><strong class="examples_text">Example:</strong></p>
|
||
<pre class="listing"><span class="Identifier">assert</span> <span class="StringLit">"abc"</span><span class="Operator">.</span><span class="Identifier">contains</span><span class="Punctuation">(</span><span class="RawData">re"bc"</span><span class="Punctuation">)</span>
|
||
<span class="Identifier">assert</span> <span class="Keyword">not</span> <span class="StringLit">"abc"</span><span class="Operator">.</span><span class="Identifier">contains</span><span class="Punctuation">(</span><span class="RawData">re"cd"</span><span class="Punctuation">)</span>
|
||
<span class="Identifier">assert</span> <span class="Keyword">not</span> <span class="StringLit">"abc"</span><span class="Operator">.</span><span class="Identifier">contains</span><span class="Punctuation">(</span><span class="RawData">re"a"</span><span class="Punctuation">,</span> <span class="Identifier">start</span> <span class="Operator">=</span> <span class="DecNumber">1</span><span class="Punctuation">)</span></pre>
|
||
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/nre2.nim#L265" class="link-seesrc" target="_blank">Source</a>
|
||
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/nre2.nim#L265" class="link-seesrc" target="_blank" >Edit</a>
|
||
|
||
</dd>
|
||
</div>
|
||
|
||
</div>
|
||
<div id="escapeRe-procs-all">
|
||
<div id="escapeRe,string">
|
||
<dt><pre><span class="Keyword">func</span> <a href="#escapeRe%2Cstring"><span class="Identifier">escapeRe</span></a><span class="Other">(</span><span class="Identifier">str</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||
<dd>
|
||
|
||
Escapes the string so it doesn't match any special characters.
|
||
<p><strong class="examples_text">Example:</strong></p>
|
||
<pre class="listing"><span class="Identifier">assert</span> <span class="Identifier">escapeRe</span><span class="Punctuation">(</span><span class="StringLit">"fly+wind"</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">"fly</span><span class="EscapeSequence">\\</span><span class="StringLit">+wind"</span>
|
||
<span class="Identifier">assert</span> <span class="Identifier">escapeRe</span><span class="Punctuation">(</span><span class="StringLit">"nim*"</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">"nim</span><span class="EscapeSequence">\\</span><span class="StringLit">*"</span></pre>
|
||
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/nre2.nim#L338" class="link-seesrc" target="_blank">Source</a>
|
||
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/nre2.nim#L338" class="link-seesrc" target="_blank" >Edit</a>
|
||
|
||
</dd>
|
||
</div>
|
||
|
||
</div>
|
||
<div id="find-procs-all">
|
||
<div id="find,string,Regex2,int">
|
||
<dt><pre><span class="Keyword">proc</span> <a href="#find%2Cstring%2CRegex2%2Cint"><span class="Identifier">find</span></a><span class="Other">(</span><span class="Identifier">str</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">pattern</span><span class="Other">:</span> <a href="#Regex"><span class="Identifier">Regex</span></a><span class="Other">;</span> <span class="Identifier">start</span> <span class="Other">=</span> <span class="DecNumber">0</span><span class="Other">;</span> <span class="Identifier">endpos</span> <span class="Other">=</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">.</span><span class="Identifier">high</span><span class="Other">)</span><span class="Other">:</span> <a href="options.html#Option"><span class="Identifier">Option</span></a><span class="Other">[</span>
|
||
<a href="#RegexMatch"><span class="Identifier">RegexMatch</span></a><span class="Other">]</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||
<dd>
|
||
|
||
Finds the given pattern in the string between the end and start positions.<dl class="docutils"><dt><tt class="docutils literal"><span class="pre"><span class="Identifier">start</span></span></tt></dt>
|
||
<dd>The start point at which to start matching. <tt class="docutils literal"><span class="pre"><span class="Operator">|</span><span class="Identifier">abc</span></span></tt> is <tt class="docutils literal"><span class="pre"><span class="DecNumber">0</span></span></tt>; <tt class="docutils literal"><span class="pre"><span class="Identifier">a</span><span class="Operator">|</span><span class="Identifier">bc</span></span></tt> is <tt class="docutils literal"><span class="pre"><span class="DecNumber">1</span></span></tt></dd>
|
||
<dt><tt class="docutils literal"><span class="pre"><span class="Identifier">endpos</span></span></tt></dt>
|
||
<dd>The maximum index for a match; <tt class="docutils literal"><span class="pre"><span class="Identifier">int</span><span class="Operator">.</span><span class="Identifier">high</span></span></tt> means the end of the string, otherwise it’s an inclusive upper bound.</dd>
|
||
</dl>
|
||
|
||
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/nre2.nim#L233" class="link-seesrc" target="_blank">Source</a>
|
||
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/nre2.nim#L233" class="link-seesrc" target="_blank" >Edit</a>
|
||
|
||
</dd>
|
||
</div>
|
||
|
||
</div>
|
||
<div id="findAll-procs-all">
|
||
<div id="findAll,string,Regex2,int">
|
||
<dt><pre><span class="Keyword">proc</span> <a href="#findAll%2Cstring%2CRegex2%2Cint"><span class="Identifier">findAll</span></a><span class="Other">(</span><span class="Identifier">str</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">pattern</span><span class="Other">:</span> <a href="#Regex"><span class="Identifier">Regex</span></a><span class="Other">;</span> <span class="Identifier">start</span> <span class="Other">=</span> <span class="DecNumber">0</span><span class="Other">;</span> <span class="Identifier">endpos</span> <span class="Other">=</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">.</span><span class="Identifier">high</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#seq"><span class="Identifier">seq</span></a><span class="Other">[</span>
|
||
<a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">]</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||
<dd>
|
||
|
||
|
||
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/nre2.nim#L260" class="link-seesrc" target="_blank">Source</a>
|
||
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/nre2.nim#L260" class="link-seesrc" target="_blank" >Edit</a>
|
||
|
||
</dd>
|
||
</div>
|
||
|
||
</div>
|
||
<div id="len-procs-all">
|
||
<div id="len">
|
||
<dt><pre><span class="Keyword">func</span> <a href="#len"><span class="Identifier">len</span></a><span class="Other">(</span><span class="Identifier">match</span><span class="Other">:</span> <a href="#Captures"><span class="Identifier">Captures</span></a> <span class="Keyword">or</span> <a href="#CaptureBounds"><span class="Identifier">CaptureBounds</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.<span class="Identifier">inline</span>.}</pre></dt>
|
||
<dd>
|
||
|
||
Return the number of capturing groups
|
||
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/nre2.nim#L119" class="link-seesrc" target="_blank">Source</a>
|
||
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/nre2.nim#L119" class="link-seesrc" target="_blank" >Edit</a>
|
||
|
||
</dd>
|
||
</div>
|
||
|
||
</div>
|
||
<div id="match-procs-all">
|
||
<div id="match,RegexMatch">
|
||
<dt><pre><span class="Keyword">func</span> <a href="#match%2CRegexMatch"><span class="Identifier">match</span></a><span class="Other">(</span><span class="Identifier">match</span><span class="Other">:</span> <a href="#RegexMatch"><span class="Identifier">RegexMatch</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> {.<span class="Identifier">inline</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
|
||
<span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||
<dd>
|
||
|
||
|
||
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/nre2.nim#L137" class="link-seesrc" target="_blank">Source</a>
|
||
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/nre2.nim#L137" class="link-seesrc" target="_blank" >Edit</a>
|
||
|
||
</dd>
|
||
</div>
|
||
<div id="match,string,Regex2,int">
|
||
<dt><pre><span class="Keyword">func</span> <a href="#match%2Cstring%2CRegex2%2Cint"><span class="Identifier">match</span></a><span class="Other">(</span><span class="Identifier">str</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">pattern</span><span class="Other">:</span> <a href="#Regex"><span class="Identifier">Regex</span></a><span class="Other">;</span> <span class="Identifier">start</span> <span class="Other">=</span> <span class="DecNumber">0</span><span class="Other">;</span> <span class="Identifier">endpos</span> <span class="Other">=</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">.</span><span class="Identifier">high</span><span class="Other">)</span><span class="Other">:</span> <a href="options.html#Option"><span class="Identifier">Option</span></a><span class="Other">[</span>
|
||
<a href="#RegexMatch"><span class="Identifier">RegexMatch</span></a><span class="Other">]</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||
<dd>
|
||
|
||
Like <a class="reference external" href="#find,string,Regex,int">find(...)</a>, but anchored to the start of the string.
|
||
<p><strong class="examples_text">Example:</strong></p>
|
||
<pre class="listing"><span class="Identifier">assert</span> <span class="StringLit">"foo"</span><span class="Operator">.</span><span class="Identifier">match</span><span class="Punctuation">(</span><span class="RawData">re"f"</span><span class="Punctuation">)</span><span class="Operator">.</span><span class="Identifier">isSome</span>
|
||
<span class="Identifier">assert</span> <span class="StringLit">"foo"</span><span class="Operator">.</span><span class="Identifier">match</span><span class="Punctuation">(</span><span class="RawData">re"o"</span><span class="Punctuation">)</span><span class="Operator">.</span><span class="Identifier">isNone</span>
|
||
|
||
<span class="Identifier">assert</span> <span class="StringLit">"abc"</span><span class="Operator">.</span><span class="Identifier">match</span><span class="Punctuation">(</span><span class="RawData">re"(\w)"</span><span class="Punctuation">)</span><span class="Operator">.</span><span class="Identifier">get</span><span class="Operator">.</span><span class="Identifier">captures</span><span class="Punctuation">[</span><span class="DecNumber">0</span><span class="Punctuation">]</span> <span class="Operator">==</span> <span class="StringLit">"a"</span>
|
||
<span class="Identifier">assert</span> <span class="StringLit">"abc"</span><span class="Operator">.</span><span class="Identifier">match</span><span class="Punctuation">(</span><span class="RawData">re"(?P<letter>\w)"</span><span class="Punctuation">)</span><span class="Operator">.</span><span class="Identifier">get</span><span class="Operator">.</span><span class="Identifier">captures</span><span class="Punctuation">[</span><span class="StringLit">"letter"</span><span class="Punctuation">]</span> <span class="Operator">==</span> <span class="StringLit">"a"</span>
|
||
<span class="Identifier">assert</span> <span class="StringLit">"abc"</span><span class="Operator">.</span><span class="Identifier">match</span><span class="Punctuation">(</span><span class="RawData">re"(\w)\w"</span><span class="Punctuation">)</span><span class="Operator">.</span><span class="Identifier">get</span><span class="Operator">.</span><span class="Identifier">captures</span><span class="Punctuation">[</span><span class="Operator">-</span><span class="DecNumber">1</span><span class="Punctuation">]</span> <span class="Operator">==</span> <span class="StringLit">"ab"</span>
|
||
|
||
<span class="Identifier">assert</span> <span class="StringLit">"abc"</span><span class="Operator">.</span><span class="Identifier">match</span><span class="Punctuation">(</span><span class="RawData">re"(\w)"</span><span class="Punctuation">)</span><span class="Operator">.</span><span class="Identifier">get</span><span class="Operator">.</span><span class="Identifier">captureBounds</span><span class="Punctuation">[</span><span class="DecNumber">0</span><span class="Punctuation">]</span> <span class="Operator">==</span> <span class="DecNumber">0</span> <span class="Operator">..</span> <span class="DecNumber">0</span>
|
||
<span class="Identifier">assert</span> <span class="DecNumber">0</span> <span class="Keyword">in</span> <span class="StringLit">"abc"</span><span class="Operator">.</span><span class="Identifier">match</span><span class="Punctuation">(</span><span class="RawData">re"(\w)"</span><span class="Punctuation">)</span><span class="Operator">.</span><span class="Identifier">get</span><span class="Operator">.</span><span class="Identifier">captureBounds</span>
|
||
<span class="Identifier">assert</span> <span class="StringLit">"abc"</span><span class="Operator">.</span><span class="Identifier">match</span><span class="Punctuation">(</span><span class="RawData">re""</span><span class="Punctuation">)</span><span class="Operator">.</span><span class="Identifier">get</span><span class="Operator">.</span><span class="Identifier">captureBounds</span><span class="Punctuation">[</span><span class="Operator">-</span><span class="DecNumber">1</span><span class="Punctuation">]</span> <span class="Operator">==</span> <span class="DecNumber">0</span> <span class="Operator">..</span> <span class="Operator">-</span><span class="DecNumber">1</span>
|
||
<span class="Identifier">assert</span> <span class="StringLit">"abc"</span><span class="Operator">.</span><span class="Identifier">match</span><span class="Punctuation">(</span><span class="RawData">re"abc"</span><span class="Punctuation">)</span><span class="Operator">.</span><span class="Identifier">get</span><span class="Operator">.</span><span class="Identifier">captureBounds</span><span class="Punctuation">[</span><span class="Operator">-</span><span class="DecNumber">1</span><span class="Punctuation">]</span> <span class="Operator">==</span> <span class="DecNumber">0</span> <span class="Operator">..</span> <span class="DecNumber">2</span></pre>
|
||
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/nre2.nim#L190" class="link-seesrc" target="_blank">Source</a>
|
||
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/nre2.nim#L190" class="link-seesrc" target="_blank" >Edit</a>
|
||
|
||
</dd>
|
||
</div>
|
||
|
||
</div>
|
||
<div id="matchBounds-procs-all">
|
||
<div id="matchBounds,RegexMatch">
|
||
<dt><pre><span class="Keyword">func</span> <a href="#matchBounds%2CRegexMatch"><span class="Identifier">matchBounds</span></a><span class="Other">(</span><span class="Identifier">match</span><span class="Other">:</span> <a href="#RegexMatch"><span class="Identifier">RegexMatch</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#HSlice"><span class="Identifier">HSlice</span></a><span class="Other">[</span><a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">,</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">]</span> {.<span class="Identifier">inline</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
|
||
<span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||
<dd>
|
||
|
||
|
||
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/nre2.nim#L140" class="link-seesrc" target="_blank">Source</a>
|
||
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/nre2.nim#L140" class="link-seesrc" target="_blank" >Edit</a>
|
||
|
||
</dd>
|
||
</div>
|
||
|
||
</div>
|
||
<div id="re-procs-all">
|
||
<div id="re,staticstring,staticRegexFlags">
|
||
<dt><pre><span class="Keyword">func</span> <a href="#re%2Cstaticstring%2CstaticRegexFlags"><span class="Identifier">re</span></a><span class="Other">(</span><span class="Identifier">pattern</span><span class="Other">:</span> <span class="Keyword">static</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">flags</span><span class="Other">:</span> <span class="Keyword">static</span> <span class="Identifier">RegexFlags</span> <span class="Other">=</span> <span class="Other">{</span><span class="Other">}</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#static"><span class="Identifier">static</span></a><span class="Other">[</span><span class="Identifier">Regex2</span><span class="Other">]</span></pre></dt>
|
||
<dd>
|
||
|
||
Parse and compile a regular expression at compile-time
|
||
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/nre2.nim#L182" class="link-seesrc" target="_blank">Source</a>
|
||
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/nre2.nim#L182" class="link-seesrc" target="_blank" >Edit</a>
|
||
|
||
</dd>
|
||
</div>
|
||
<div id="re,string,RegexFlags">
|
||
<dt><pre><span class="Keyword">func</span> <a href="#re%2Cstring%2CRegexFlags"><span class="Identifier">re</span></a><span class="Other">(</span><span class="Identifier">pattern</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">flags</span><span class="Other">:</span> <span class="Identifier">RegexFlags</span> <span class="Other">=</span> <span class="Other">{</span><span class="Other">}</span><span class="Other">)</span><span class="Other">:</span> <a href="#Regex"><span class="Identifier">Regex</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">RegexError</span><span class="Other">]</span><span class="Other">,</span>
|
||
<span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||
<dd>
|
||
|
||
Parse and compile a regular expression at run-time
|
||
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/nre2.nim#L186" class="link-seesrc" target="_blank">Source</a>
|
||
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/nre2.nim#L186" class="link-seesrc" target="_blank" >Edit</a>
|
||
|
||
</dd>
|
||
</div>
|
||
|
||
</div>
|
||
<div id="replace-procs-all">
|
||
<div id="replace,string,Regex2,string">
|
||
<dt><pre><span class="Keyword">proc</span> <a href="#replace%2Cstring%2CRegex2%2Cstring"><span class="Identifier">replace</span></a><span class="Other">(</span><span class="Identifier">str</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">pattern</span><span class="Other">:</span> <a href="#Regex"><span class="Identifier">Regex</span></a><span class="Other">;</span> <span class="Identifier">sub</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> {.
|
||
<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">ValueError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||
<dd>
|
||
|
||
|
||
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/nre2.nim#L335" class="link-seesrc" target="_blank">Source</a>
|
||
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/nre2.nim#L335" class="link-seesrc" target="_blank" >Edit</a>
|
||
|
||
</dd>
|
||
</div>
|
||
<div id="replace,string,Regex2,proc(RegexMatch)">
|
||
<dt><pre><span class="Keyword">proc</span> <a href="#replace%2Cstring%2CRegex2%2Cproc%28RegexMatch%29"><span class="Identifier">replace</span></a><span class="Other">(</span><span class="Identifier">str</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">pattern</span><span class="Other">:</span> <a href="#Regex"><span class="Identifier">Regex</span></a><span class="Other">;</span>
|
||
<span class="Identifier">subproc</span><span class="Other">:</span> <span class="Keyword">proc</span> <span class="Other">(</span><span class="Identifier">match</span><span class="Other">:</span> <a href="#RegexMatch"><span class="Identifier">RegexMatch</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> {.
|
||
<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">Exception</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||
<dd>
|
||
|
||
<p>Replaces each match of Regex in the string with <tt class="docutils literal"><span class="pre"><span class="Identifier">subproc</span></span></tt>, which should never be or return <tt class="docutils literal"><span class="pre"><span class="Keyword">nil</span></span></tt>.</p>
|
||
<p>If <tt class="docutils literal"><span class="pre"><span class="Identifier">subproc</span></span></tt> is a <tt class="docutils literal"><span class="pre"><span class="Keyword">proc</span> <span class="Punctuation">(</span><span class="Identifier">RegexMatch</span><span class="Punctuation">)</span><span class="Punctuation">:</span> <span class="Identifier">string</span></span></tt>, then it is executed with each match and the return value is the replacement value.</p>
|
||
<p>If <tt class="docutils literal"><span class="pre"><span class="Identifier">subproc</span></span></tt> is a <tt class="docutils literal"><span class="pre"><span class="Keyword">proc</span> <span class="Punctuation">(</span><span class="Identifier">string</span><span class="Punctuation">)</span><span class="Punctuation">:</span> <span class="Identifier">string</span></span></tt>, then it is executed with the full text of the match and the return value is the replacement value.</p>
|
||
<p>If <tt class="docutils literal"><span class="pre"><span class="Identifier">subproc</span></span></tt> is a string, the syntax is as follows:</p>
|
||
<ul class="simple"><li><tt class="docutils literal"><span class="pre"><span class="Operator">$$</span></span></tt> - literal <tt class="docutils literal"><span class="pre"><span class="Operator">$</span></span></tt></li>
|
||
<li><tt class="docutils literal"><span class="pre"><span class="Operator">$</span><span class="DecNumber">123</span></span></tt> - capture number <tt class="docutils literal"><span class="pre"><span class="DecNumber">123</span></span></tt></li>
|
||
<li><tt class="docutils literal"><span class="pre"><span class="Operator">$</span><span class="DecNumber">1</span><span class="Operator">$</span><span class="Comment">#</span></span></tt> - first and second captures</li>
|
||
<li><tt class="docutils literal"><span class="pre"><span class="Operator">$</span><span class="Comment">#</span></span></tt> - first capture</li>
|
||
</ul>
|
||
<p>Following syntax is not supported in NRE2</p>
|
||
<ul class="simple"><li><tt class="docutils literal"><span class="pre"><span class="Operator">$</span><span class="Identifier">foo</span></span></tt> - named capture <tt class="docutils literal"><span class="pre"><span class="Identifier">foo</span></span></tt></li>
|
||
<li><tt class="docutils literal"><span class="pre"><span class="Operator">$</span><span class="Punctuation">{</span><span class="Identifier">foo</span><span class="Punctuation">}</span></span></tt> - same as above</li>
|
||
<li><tt class="docutils literal"><span class="pre"><span class="Operator">$</span><span class="DecNumber">0</span></span></tt> - full match</li>
|
||
</ul>
|
||
<p>If a given capture is missing, <tt class="docutils literal"><span class="pre"><span class="Identifier">ValueError</span></span></tt> is thrown.</p>
|
||
|
||
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/nre2.nim#L297" class="link-seesrc" target="_blank">Source</a>
|
||
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/nre2.nim#L297" class="link-seesrc" target="_blank" >Edit</a>
|
||
|
||
</dd>
|
||
</div>
|
||
<div id="replace,string,Regex2,proc(string)">
|
||
<dt><pre><span class="Keyword">proc</span> <a href="#replace%2Cstring%2CRegex2%2Cproc%28string%29"><span class="Identifier">replace</span></a><span class="Other">(</span><span class="Identifier">str</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">pattern</span><span class="Other">:</span> <a href="#Regex"><span class="Identifier">Regex</span></a><span class="Other">;</span> <span class="Identifier">subproc</span><span class="Other">:</span> <span class="Keyword">proc</span> <span class="Other">(</span><span class="Identifier">match</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> {.
|
||
<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">Exception</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||
<dd>
|
||
|
||
|
||
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/nre2.nim#L328" class="link-seesrc" target="_blank">Source</a>
|
||
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/nre2.nim#L328" class="link-seesrc" target="_blank" >Edit</a>
|
||
|
||
</dd>
|
||
</div>
|
||
|
||
</div>
|
||
<div id="split-procs-all">
|
||
<div id="split,string,Regex2,int,int">
|
||
<dt><pre><span class="Keyword">proc</span> <a href="#split%2Cstring%2CRegex2%2Cint%2Cint"><span class="Identifier">split</span></a><span class="Other">(</span><span class="Identifier">str</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">pattern</span><span class="Other">:</span> <a href="#Regex"><span class="Identifier">Regex</span></a><span class="Other">;</span> <span class="Identifier">maxSplit</span> <span class="Other">=</span> <span class="DecNumber">-1</span><span class="Other">;</span> <span class="Identifier">start</span> <span class="Other">=</span> <span class="DecNumber">0</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#seq"><span class="Identifier">seq</span></a><span class="Other">[</span><a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">]</span> {.
|
||
<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||
<dd>
|
||
|
||
<p>Splits the string with the given regex. This works according to the rules that Perl and Javascript use.</p>
|
||
<p><tt class="docutils literal"><span class="pre"><span class="Identifier">start</span></span></tt> behaves the same as in <a class="reference external" href="#find,string,Regex,int">find(...)</a>. </p>
|
||
|
||
<p><strong class="examples_text">Example:</strong></p>
|
||
<pre class="listing"><span class="Comment"># - If the match is zero-width, then the string is still split:</span>
|
||
<span class="Identifier">assert</span> <span class="StringLit">"123"</span><span class="Operator">.</span><span class="Identifier">split</span><span class="Punctuation">(</span><span class="RawData">re""</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="Operator">@</span><span class="Punctuation">[</span><span class="StringLit">"1"</span><span class="Punctuation">,</span> <span class="StringLit">"2"</span><span class="Punctuation">,</span> <span class="StringLit">"3"</span><span class="Punctuation">]</span>
|
||
|
||
<span class="Comment"># - If the pattern has a capture in it, it is added after the string</span>
|
||
<span class="Comment"># split:</span>
|
||
<span class="Identifier">assert</span> <span class="StringLit">"12"</span><span class="Operator">.</span><span class="Identifier">split</span><span class="Punctuation">(</span><span class="RawData">re"(\d)"</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="Operator">@</span><span class="Punctuation">[</span><span class="StringLit">""</span><span class="Punctuation">,</span> <span class="StringLit">"1"</span><span class="Punctuation">,</span> <span class="StringLit">""</span><span class="Punctuation">,</span> <span class="StringLit">"2"</span><span class="Punctuation">,</span> <span class="StringLit">""</span><span class="Punctuation">]</span>
|
||
|
||
<span class="Comment"># - If `maxsplit != -1`, then the string will only be split</span>
|
||
<span class="Comment"># `maxsplit - 1` times. This means that there will be `maxsplit`</span>
|
||
<span class="Comment"># strings in the output seq.</span>
|
||
<span class="Identifier">assert</span> <span class="StringLit">"1.2.3"</span><span class="Operator">.</span><span class="Identifier">split</span><span class="Punctuation">(</span><span class="RawData">re"\."</span><span class="Punctuation">,</span> <span class="Identifier">maxsplit</span> <span class="Operator">=</span> <span class="DecNumber">2</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="Operator">@</span><span class="Punctuation">[</span><span class="StringLit">"1"</span><span class="Punctuation">,</span> <span class="StringLit">"2.3"</span><span class="Punctuation">]</span></pre>
|
||
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/nre2.nim#L276" class="link-seesrc" target="_blank">Source</a>
|
||
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/nre2.nim#L276" class="link-seesrc" target="_blank" >Edit</a>
|
||
|
||
</dd>
|
||
</div>
|
||
|
||
</div>
|
||
<div id="toSeq-procs-all">
|
||
<div id="toSeq,CaptureBounds">
|
||
<dt><pre><span class="Keyword">func</span> <a href="#toSeq%2CCaptureBounds"><span class="Identifier">toSeq</span></a><span class="Other">(</span><span class="Identifier">match</span><span class="Other">:</span> <a href="#CaptureBounds"><span class="Identifier">CaptureBounds</span></a><span class="Other">;</span> <span class="Identifier">default</span> <span class="Other">=</span> <span class="Identifier">none</span><span class="Other">(</span><a href="system.html#HSlice"><span class="Identifier">HSlice</span></a><span class="Other">[</span><a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">,</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">]</span><span class="Other">)</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#seq"><span class="Identifier">seq</span></a><span class="Other">[</span>
|
||
<a href="options.html#Option"><span class="Identifier">Option</span></a><span class="Other">[</span><a href="system.html#HSlice"><span class="Identifier">HSlice</span></a><span class="Other">[</span><a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">,</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">]</span><span class="Other">]</span><span class="Other">]</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||
<dd>
|
||
|
||
|
||
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/nre2.nim#L169" class="link-seesrc" target="_blank">Source</a>
|
||
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/nre2.nim#L169" class="link-seesrc" target="_blank" >Edit</a>
|
||
|
||
</dd>
|
||
</div>
|
||
<div id="toSeq,Captures,Option[string]">
|
||
<dt><pre><span class="Keyword">func</span> <a href="#toSeq%2CCaptures%2COption%5Bstring%5D"><span class="Identifier">toSeq</span></a><span class="Other">(</span><span class="Identifier">match</span><span class="Other">:</span> <a href="#Captures"><span class="Identifier">Captures</span></a><span class="Other">;</span> <span class="Identifier">default</span><span class="Other">:</span> <a href="options.html#Option"><span class="Identifier">Option</span></a><span class="Other">[</span><a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">]</span> <span class="Other">=</span> <span class="Identifier">none</span><span class="Other">(</span><a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#seq"><span class="Identifier">seq</span></a><span class="Other">[</span>
|
||
<a href="options.html#Option"><span class="Identifier">Option</span></a><span class="Other">[</span><a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">]</span><span class="Other">]</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||
<dd>
|
||
|
||
|
||
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/nre2.nim#L174" class="link-seesrc" target="_blank">Source</a>
|
||
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/nre2.nim#L174" class="link-seesrc" target="_blank" >Edit</a>
|
||
|
||
</dd>
|
||
</div>
|
||
|
||
</div>
|
||
<div id="toTable-procs-all">
|
||
<div id="toTable,CaptureBounds">
|
||
<dt><pre><span class="Keyword">func</span> <a href="#toTable%2CCaptureBounds"><span class="Identifier">toTable</span></a><span class="Other">(</span><span class="Identifier">match</span><span class="Other">:</span> <a href="#CaptureBounds"><span class="Identifier">CaptureBounds</span></a><span class="Other">)</span><span class="Other">:</span> <a href="tables.html#Table"><span class="Identifier">Table</span></a><span class="Other">[</span><a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">,</span> <a href="system.html#HSlice"><span class="Identifier">HSlice</span></a><span class="Other">[</span><a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">,</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">]</span><span class="Other">]</span> {.
|
||
<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||
<dd>
|
||
|
||
|
||
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/nre2.nim#L154" class="link-seesrc" target="_blank">Source</a>
|
||
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/nre2.nim#L154" class="link-seesrc" target="_blank" >Edit</a>
|
||
|
||
</dd>
|
||
</div>
|
||
<div id="toTable,Captures">
|
||
<dt><pre><span class="Keyword">func</span> <a href="#toTable%2CCaptures"><span class="Identifier">toTable</span></a><span class="Other">(</span><span class="Identifier">match</span><span class="Other">:</span> <a href="#Captures"><span class="Identifier">Captures</span></a><span class="Other">)</span><span class="Other">:</span> <a href="tables.html#Table"><span class="Identifier">Table</span></a><span class="Other">[</span><a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">,</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">]</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
|
||
<span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||
<dd>
|
||
|
||
|
||
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/nre2.nim#L147" class="link-seesrc" target="_blank">Source</a>
|
||
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/nre2.nim#L147" class="link-seesrc" target="_blank" >Edit</a>
|
||
|
||
</dd>
|
||
</div>
|
||
|
||
</div>
|
||
|
||
</dl>
|
||
</div>
|
||
<div class="section" id="15">
|
||
<h1><a class="toc-backref" href="#15">Iterators</a></h1>
|
||
<dl class="item">
|
||
<div id="findIter-iterators-all">
|
||
<div id="findIter.i,string,Regex2,int">
|
||
<dt><pre><span class="Keyword">iterator</span> <a href="#findIter.i%2Cstring%2CRegex2%2Cint"><span class="Identifier">findIter</span></a><span class="Other">(</span><span class="Identifier">str</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">pattern</span><span class="Other">:</span> <a href="#Regex"><span class="Identifier">Regex</span></a><span class="Other">;</span> <span class="Identifier">start</span> <span class="Other">=</span> <span class="DecNumber">0</span><span class="Other">;</span> <span class="Identifier">endpos</span> <span class="Other">=</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">.</span><span class="Identifier">high</span><span class="Other">)</span><span class="Other">:</span> <a href="#RegexMatch"><span class="Identifier">RegexMatch</span></a> {.
|
||
<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||
<dd>
|
||
|
||
Works the same as <a class="reference external" href="#find,string,Regex,int">find(...)</a>, but finds every non-overlapping match:
|
||
<p><strong class="examples_text">Example:</strong></p>
|
||
<pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">sugar</span>
|
||
<span class="Identifier">assert</span> <span class="Identifier">collect</span><span class="Punctuation">(</span><span class="Keyword">for</span> <span class="Identifier">a</span> <span class="Keyword">in</span> <span class="StringLit">"2222"</span><span class="Operator">.</span><span class="Identifier">findIter</span><span class="Punctuation">(</span><span class="RawData">re"22"</span><span class="Punctuation">)</span><span class="Punctuation">:</span> <span class="Identifier">a</span><span class="Operator">.</span><span class="Identifier">match</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="Operator">@</span><span class="Punctuation">[</span><span class="StringLit">"22"</span><span class="Punctuation">,</span> <span class="StringLit">"22"</span><span class="Punctuation">]</span>
|
||
<span class="Comment"># not @["22", "22", "22"]</span></pre><p>Arguments are the same as <a class="reference external" href="#find,string,Regex,int">find(...)</a></p>
|
||
<p>Variants:</p>
|
||
<ul class="simple"><li><tt class="docutils literal"><span class="pre"><span class="Keyword">proc</span> <span class="Identifier">findAll</span><span class="Punctuation">(</span><span class="Operator">...</span><span class="Punctuation">)</span></span></tt> returns a <tt class="docutils literal"><span class="pre"><span class="Identifier">seq</span><span class="Punctuation">[</span><span class="Identifier">string</span><span class="Punctuation">]</span></span></tt></li>
|
||
</ul>
|
||
|
||
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/nre2.nim#L213" class="link-seesrc" target="_blank">Source</a>
|
||
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/nre2.nim#L213" class="link-seesrc" target="_blank" >Edit</a>
|
||
|
||
</dd>
|
||
</div>
|
||
|
||
</div>
|
||
<div id="items-iterators-all">
|
||
<div id="items.i,CaptureBounds">
|
||
<dt><pre><span class="Keyword">iterator</span> <a href="#items.i%2CCaptureBounds"><span class="Identifier">items</span></a><span class="Other">(</span><span class="Identifier">match</span><span class="Other">:</span> <a href="#CaptureBounds"><span class="Identifier">CaptureBounds</span></a><span class="Other">;</span> <span class="Identifier">default</span> <span class="Other">=</span> <span class="Identifier">none</span><span class="Other">(</span><a href="system.html#HSlice"><span class="Identifier">HSlice</span></a><span class="Other">[</span><a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">,</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">]</span><span class="Other">)</span><span class="Other">)</span><span class="Other">:</span> <a href="options.html#Option"><span class="Identifier">Option</span></a><span class="Other">[</span>
|
||
<a href="system.html#HSlice"><span class="Identifier">HSlice</span></a><span class="Other">[</span><a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">,</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">]</span><span class="Other">]</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||
<dd>
|
||
|
||
|
||
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/nre2.nim#L161" class="link-seesrc" target="_blank">Source</a>
|
||
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/nre2.nim#L161" class="link-seesrc" target="_blank" >Edit</a>
|
||
|
||
</dd>
|
||
</div>
|
||
<div id="items.i,Captures">
|
||
<dt><pre><span class="Keyword">iterator</span> <a href="#items.i%2CCaptures"><span class="Identifier">items</span></a><span class="Other">(</span><span class="Identifier">match</span><span class="Other">:</span> <a href="#Captures"><span class="Identifier">Captures</span></a><span class="Other">;</span> <span class="Identifier">default</span> <span class="Other">=</span> <span class="Identifier">none</span><span class="Other">(</span><a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span><span class="Other">)</span><span class="Other">:</span> <a href="options.html#Option"><span class="Identifier">Option</span></a><span class="Other">[</span><a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">]</span> {.
|
||
<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||
<dd>
|
||
|
||
|
||
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/nre2.nim#L165" class="link-seesrc" target="_blank">Source</a>
|
||
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/nre2.nim#L165" class="link-seesrc" target="_blank" >Edit</a>
|
||
|
||
</dd>
|
||
</div>
|
||
|
||
</div>
|
||
|
||
</dl>
|
||
</div>
|
||
<div class="section" id="19">
|
||
<h1><a class="toc-backref" href="#19">Exports</a></h1>
|
||
<dl class="item">
|
||
<a href="options.html#$,Option[T]"><span class="Identifier">$</span></a>, <a href="options.html#none"><span class="Identifier">none</span></a>, <a href="options.html#flatten,Option[Option[T]]"><span class="Identifier">flatten</span></a>, <a href="options.html#none,typedesc"><span class="Identifier">none</span></a>, <a href="options.html#==,Option[T],Option[T]"><span class="Identifier">==</span></a>, <a href="options.html#get,Option[T]"><span class="Identifier">get</span></a>, <a href="options.html#map,Option[T],proc(T)"><span class="Identifier">map</span></a>, <a href="options.html#get,Option[T]_2"><span class="Identifier">get</span></a>, <a href="options.html#map,Option[T],proc(T)_2"><span class="Identifier">map</span></a>, <a href="options.html#UnpackDefect"><span class="Identifier">UnpackDefect</span></a>, <a href="options.html#Option"><span class="Identifier">Option</span></a>, <a href="options.html#get,Option[T],T"><span class="Identifier">get</span></a>, <a href="options.html#unsafeGet,Option[T]"><span class="Identifier">unsafeGet</span></a>, <a href="options.html#option,sinkT"><span class="Identifier">option</span></a>, <a href="options.html#UnpackError"><span class="Identifier">UnpackError</span></a>, <a href="options.html#flatMap,Option[T],proc(T)"><span class="Identifier">flatMap</span></a>, <a href="options.html#isSome,Option[T]"><span class="Identifier">isSome</span></a>, <a href="options.html#some,sinkT"><span class="Identifier">some</span></a>, <a href="options.html#filter,Option[T],proc(T)"><span class="Identifier">filter</span></a>, <a href="options.html#isNone,Option[T]"><span class="Identifier">isNone</span></a>
|
||
</dl>
|
||
</div>
|
||
|
||
</div>
|
||
</div>
|
||
|
||
<div class="twelve-columns footer">
|
||
<span class="nim-sprite"></span>
|
||
<br>
|
||
<small style="color: var(--hint);">Made with Nim. Generated: 2026-05-27 21:40:36 UTC</small>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<script defer data-domain="nim-lang.org" src="https://plausible.io/js/plausible.js"></script>
|
||
|
||
</body>
|
||
</html>
|