nre.html 122 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <!-- This file is generated by Nim. -->
  4. <html xmlns="https://www.w3.org/1999/xhtml" xml:lang="en" lang="en" data-theme="auto">
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  7. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  8. <title>std/nre</title>
  9. <!-- Google fonts -->
  10. <link href='https://fonts.googleapis.com/css?family=Lato:400,600,900' rel='stylesheet' type='text/css'/>
  11. <link href='https://fonts.googleapis.com/css?family=Source+Code+Pro:400,500,600' rel='stylesheet' type='text/css'/>
  12. <!-- Favicon -->
  13. <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=="/>
  14. <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=">
  15. <!-- CSS -->
  16. <link rel="stylesheet" type="text/css" href="nimdoc.out.css?v=2.3.1">
  17. <!-- JS -->
  18. <script type="text/javascript" src="dochack.js?v=2.3.1"></script>
  19. </head>
  20. <body>
  21. <div class="document" id="documentId">
  22. <div class="container">
  23. <h1 class="title">std/nre</h1>
  24. <div class="row">
  25. <div class="three columns">
  26. <div class="theme-select-wrapper">
  27. <label for="theme-select">Theme:&nbsp;</label>
  28. <select id="theme-select" onchange="setTheme(this.value)">
  29. <option value="auto">🌗 Match OS</option>
  30. <option value="dark">🌑 Dark</option>
  31. <option value="light">🌕 Light</option>
  32. </select>
  33. </div>
  34. <div id="global-links">
  35. <ul class="simple-boot">
  36. <li><a href="manual.html">Manual</a></li>
  37. <li><a href="lib.html">Standard library</a></li>
  38. <li> <a id="indexLink" href="theindex.html">Index</a></li>
  39. <li><a href="compiler/theindex.html">Compiler docs</a></li>
  40. <li><a href="https://nim-lang.github.io/fusion/theindex.html">Fusion docs</a></li>
  41. <li><a href="https://nim-lang.github.io/Nim/">devel</a>, <a href="https://nim-lang.org/documentation.html">stable</a></li>
  42. </ul>
  43. </div>
  44. <div id="searchInputDiv">
  45. Search: <input type="search" id="searchInput"
  46. oninput="search()" />
  47. </div>
  48. <ul class="simple simple-toc" id="toc-list">
  49. <ul class="simple"><li><a class="reference" id="licencing-options_toc" href="#licencing-options">Options</a></li>
  50. </ul><li><a class="reference" id="what-is-nreqmark_toc" href="#what-is-nreqmark">What is NRE?</a></li>
  51. <ul class="simple"><li><a class="reference" id="what-is-nreqmark-licencing_toc" href="#what-is-nreqmark-licencing">Licencing</a></li>
  52. </ul><li>
  53. <a class="reference reference-toplevel" href="#6" id="56">Imports</a>
  54. </li>
  55. <li>
  56. <details open>
  57. <summary><a class="reference reference-toplevel" href="#7" id="57">Types</a></summary>
  58. <ul class="simple simple-toc-section">
  59. <li><a class="reference" href="#CaptureBounds" title="CaptureBounds = distinct RegexMatch">CaptureBounds</a></li>
  60. <li><a class="reference" href="#Captures" title="Captures = distinct RegexMatch">Captures</a></li>
  61. <li><a class="reference" href="#InvalidUnicodeError" title="InvalidUnicodeError = ref object of RegexError
  62. pos*: int ## the location of the invalid unicode in bytes">InvalidUnicodeError</a></li>
  63. <li><a class="reference" href="#Regex" title="Regex = ref RegexDesc">Regex</a></li>
  64. <li><a class="reference" href="#RegexDesc" title="RegexDesc = object
  65. pattern*: string
  66. ## not nil
  67. ## nil">RegexDesc</a></li>
  68. <li><a class="reference" href="#RegexError" title="RegexError = ref object of CatchableError">RegexError</a></li>
  69. <li><a class="reference" href="#RegexInternalError" title="RegexInternalError = ref object of RegexError">RegexInternalError</a></li>
  70. <li><a class="reference" href="#RegexMatch" title="RegexMatch = object
  71. pattern*: Regex ## The regex doing the matching.
  72. ## Not nil.
  73. str*: string ## The string that was matched against.
  74. ## First item is the bounds of the match
  75. ## Other items are the captures
  76. ## `a` is inclusive start, `b` is exclusive end">RegexMatch</a></li>
  77. <li><a class="reference" href="#StudyError" title="StudyError = ref object of RegexError">StudyError</a></li>
  78. <li><a class="reference" href="#SyntaxError" title="SyntaxError = ref object of RegexError
  79. pos*: int ## the location of the syntax error in bytes
  80. pattern*: string ## the pattern that caused the problem">SyntaxError</a></li>
  81. </ul>
  82. </details>
  83. </li>
  84. <li>
  85. <details open>
  86. <summary><a class="reference reference-toplevel" href="#12" id="62">Procs</a></summary>
  87. <ul class="simple simple-toc-section">
  88. <ul class="simple nested-toc-section">$
  89. <li><a class="reference" href="#%24%2CRegexMatch" title="`$`(pattern: RegexMatch): string">`$`(pattern: RegexMatch): string</a></li>
  90. </ul>
  91. <ul class="simple nested-toc-section">==
  92. <li><a class="reference" href="#%3D%3D%2CRegex%2CRegex" title="`==`(a, b: Regex): bool">`==`(a, b: Regex): bool</a></li>
  93. <li><a class="reference" href="#%3D%3D%2CRegexMatch%2CRegexMatch" title="`==`(a, b: RegexMatch): bool">`==`(a, b: RegexMatch): bool</a></li>
  94. </ul>
  95. <ul class="simple nested-toc-section">[]
  96. <li><a class="reference" href="#%5B%5D%2CCaptureBounds%2Cint" title="`[]`(pattern: CaptureBounds; i: int): HSlice[int, int]">`[]`(pattern: CaptureBounds; i: int): HSlice[int, int]</a></li>
  97. <li><a class="reference" href="#%5B%5D%2CCaptureBounds%2Cstring" title="`[]`(pattern: CaptureBounds; name: string): HSlice[int, int]">`[]`(pattern: CaptureBounds; name: string): HSlice[int, int]</a></li>
  98. <li><a class="reference" href="#%5B%5D%2CCaptures%2Cint" title="`[]`(pattern: Captures; i: int): string">`[]`(pattern: Captures; i: int): string</a></li>
  99. <li><a class="reference" href="#%5B%5D%2CCaptures%2Cstring" title="`[]`(pattern: Captures; name: string): string">`[]`(pattern: Captures; name: string): string</a></li>
  100. </ul>
  101. <ul class="simple nested-toc-section">captureBounds
  102. <li><a class="reference" href="#captureBounds%2CRegexMatch" title="captureBounds(pattern: RegexMatch): CaptureBounds">captureBounds(pattern: RegexMatch): CaptureBounds</a></li>
  103. </ul>
  104. <ul class="simple nested-toc-section">captureCount
  105. <li><a class="reference" href="#captureCount%2CRegex" title="captureCount(pattern: Regex): int">captureCount(pattern: Regex): int</a></li>
  106. </ul>
  107. <ul class="simple nested-toc-section">captureNameId
  108. <li><a class="reference" href="#captureNameId%2CRegex" title="captureNameId(pattern: Regex): Table[string, int]">captureNameId(pattern: Regex): Table[string, int]</a></li>
  109. </ul>
  110. <ul class="simple nested-toc-section">captures
  111. <li><a class="reference" href="#captures%2CRegexMatch" title="captures(pattern: RegexMatch): Captures">captures(pattern: RegexMatch): Captures</a></li>
  112. </ul>
  113. <ul class="simple nested-toc-section">contains
  114. <li><a class="reference" href="#contains%2CCaptureBounds%2Cint" title="contains(pattern: CaptureBounds; i: int): bool">contains(pattern: CaptureBounds; i: int): bool</a></li>
  115. <li><a class="reference" href="#contains%2CCaptureBounds%2Cstring" title="contains(pattern: CaptureBounds; name: string): bool">contains(pattern: CaptureBounds; name: string): bool</a></li>
  116. <li><a class="reference" href="#contains%2CCaptures%2Cint" title="contains(pattern: Captures; i: int): bool">contains(pattern: Captures; i: int): bool</a></li>
  117. <li><a class="reference" href="#contains%2CCaptures%2Cstring" title="contains(pattern: Captures; name: string): bool">contains(pattern: Captures; name: string): bool</a></li>
  118. <li><a class="reference" href="#contains%2Cstring%2CRegex%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>
  119. </ul>
  120. <ul class="simple nested-toc-section">escapeRe
  121. <li><a class="reference" href="#escapeRe%2Cstring" title="escapeRe(str: string): string">escapeRe(str: string): string</a></li>
  122. </ul>
  123. <ul class="simple nested-toc-section">find
  124. <li><a class="reference" href="#find%2Cstring%2CRegex%2Cint" title="find(str: string; pattern: Regex; start = 0; endpos = int.high): Option[
  125. RegexMatch]">find(str: string; pattern: Regex; start = 0; endpos = int.high): Option[
  126. RegexMatch]</a></li>
  127. </ul>
  128. <ul class="simple nested-toc-section">findAll
  129. <li><a class="reference" href="#findAll%2Cstring%2CRegex%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>
  130. </ul>
  131. <ul class="simple nested-toc-section">match
  132. <li><a class="reference" href="#match%2CRegexMatch" title="match(pattern: RegexMatch): string">match(pattern: RegexMatch): string</a></li>
  133. <li><a class="reference" href="#match%2Cstring%2CRegex%2Cint" title="match(str: string; pattern: Regex; start = 0; endpos = int.high): Option[
  134. RegexMatch]">match(str: string; pattern: Regex; start = 0; endpos = int.high): Option[
  135. RegexMatch]</a></li>
  136. </ul>
  137. <ul class="simple nested-toc-section">matchBounds
  138. <li><a class="reference" href="#matchBounds%2CRegexMatch" title="matchBounds(pattern: RegexMatch): HSlice[int, int]">matchBounds(pattern: RegexMatch): HSlice[int, int]</a></li>
  139. </ul>
  140. <ul class="simple nested-toc-section">re
  141. <li><a class="reference" href="#re%2Cstring" title="re(pattern: string): Regex">re(pattern: string): Regex</a></li>
  142. </ul>
  143. <ul class="simple nested-toc-section">replace
  144. <li><a class="reference" href="#replace%2Cstring%2CRegex%2Cstring" title="replace(str: string; pattern: Regex; sub: string): string">replace(str: string; pattern: Regex; sub: string): string</a></li>
  145. <li><a class="reference" href="#replace%2Cstring%2CRegex%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>
  146. <li><a class="reference" href="#replace%2Cstring%2CRegex%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>
  147. </ul>
  148. <ul class="simple nested-toc-section">split
  149. <li><a class="reference" href="#split%2Cstring%2CRegex%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>
  150. </ul>
  151. <ul class="simple nested-toc-section">toSeq
  152. <li><a class="reference" href="#toSeq%2CCaptureBounds" title="toSeq(pattern: CaptureBounds; default = none(HSlice[int, int])): seq[
  153. Option[HSlice[int, int]]]">toSeq(pattern: CaptureBounds; default = none(HSlice[int, int])): seq[
  154. Option[HSlice[int, int]]]</a></li>
  155. <li><a class="reference" href="#toSeq%2CCaptures%2COption%5Bstring%5D" title="toSeq(pattern: Captures; default: Option[string] = none(string)): seq[
  156. Option[string]]">toSeq(pattern: Captures; default: Option[string] = none(string)): seq[
  157. Option[string]]</a></li>
  158. </ul>
  159. <ul class="simple nested-toc-section">toTable
  160. <li><a class="reference" href="#toTable%2CCaptureBounds" title="toTable(pattern: CaptureBounds): Table[string, HSlice[int, int]]">toTable(pattern: CaptureBounds): Table[string, HSlice[int, int]]</a></li>
  161. <li><a class="reference" href="#toTable%2CCaptures" title="toTable(pattern: Captures): Table[string, string]">toTable(pattern: Captures): Table[string, string]</a></li>
  162. </ul>
  163. </ul>
  164. </details>
  165. </li>
  166. <li>
  167. <details open>
  168. <summary><a class="reference reference-toplevel" href="#15" id="65">Iterators</a></summary>
  169. <ul class="simple simple-toc-section">
  170. <ul class="simple nested-toc-section">findIter
  171. <li><a class="reference" href="#findIter.i%2Cstring%2CRegex%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>
  172. </ul>
  173. <ul class="simple nested-toc-section">items
  174. <li><a class="reference" href="#items.i%2CCaptureBounds" title="items(pattern: CaptureBounds; default = none(HSlice[int, int])): Option[
  175. HSlice[int, int]]">items(pattern: CaptureBounds; default = none(HSlice[int, int])): Option[
  176. HSlice[int, int]]</a></li>
  177. <li><a class="reference" href="#items.i%2CCaptures%2COption%5Bstring%5D" title="items(pattern: Captures; default: Option[string] = none(string)): Option[string]">items(pattern: Captures; default: Option[string] = none(string)): Option[string]</a></li>
  178. </ul>
  179. </ul>
  180. </details>
  181. </li>
  182. </ul>
  183. </div>
  184. <div class="nine columns" id="content">
  185. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/nre.nim#L1" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  186. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/nre.nim#L1" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  187. <div id="tocRoot"></div>
  188. <p class="module-desc">
  189. <h1><a class="toc-backref" id="what-is-nreqmark" href="#what-is-nreqmark">What is NRE?</a></h1><p>A regular expression library for Nim using PCRE to do the hard work.</p>
  190. <p>For documentation on how to write patterns, there exists <a class="reference external" href="https://www.pcre.org/original/doc/html/pcrepattern.html">the official PCRE pattern documentation</a>. You can also search the internet for a wide variety of third-party documentation and tools.</p>
  191. <div class="admonition admonition-warning"><span class="admonition-warning-text"><b>Warning:</b></span>
  192. If you love <tt class="docutils literal"><span class="pre"><span class="Identifier">sequtils</span><span class="Operator">.</span><span class="Identifier">toSeq</span></span></tt> we have bad news for you. This library doesn't work with it due to documented compiler limitations. As a workaround, use this:</div>
  193. <p><strong class="examples_text">Example:</strong></p>
  194. <pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">nre</span>
  195. <span class="Comment"># either `import std/nre except toSeq` or fully qualify `sequtils.toSeq`:</span>
  196. <span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">sequtils</span>
  197. <span class="Keyword">iterator</span> <span class="Identifier">iota</span><span class="Punctuation">(</span><span class="Identifier">n</span><span class="Punctuation">:</span> <span class="Identifier">int</span><span class="Punctuation">)</span><span class="Punctuation">:</span> <span class="Identifier">int</span> <span class="Operator">=</span>
  198. <span class="Keyword">for</span> <span class="Identifier">i</span> <span class="Keyword">in</span> <span class="FloatNumber">0.</span><span class="Operator">.&lt;</span><span class="Identifier">n</span><span class="Punctuation">:</span> <span class="Keyword">yield</span> <span class="Identifier">i</span>
  199. <span class="Identifier">assert</span> <span class="Identifier">sequtils</span><span class="Operator">.</span><span class="Identifier">toSeq</span><span class="Punctuation">(</span><span class="Identifier">iota</span><span class="Punctuation">(</span><span class="DecNumber">3</span><span class="Punctuation">)</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="Operator">@</span><span class="Punctuation">[</span><span class="DecNumber">0</span><span class="Punctuation">,</span> <span class="DecNumber">1</span><span class="Punctuation">,</span> <span class="DecNumber">2</span><span class="Punctuation">]</span></pre><div class="admonition admonition-info"><span class="admonition-info-text"><b>Note:</b></span>
  200. There are also alternative nimble packages such as <a class="reference external" href="https://github.com/khchen/tinyre">tinyre</a> and <a class="reference external" href="https://github.com/nitely/nim-regex">regex</a>.</div>
  201. <h2><a class="toc-backref" id="what-is-nreqmark-licencing" href="#what-is-nreqmark-licencing">Licencing</a></h2><p>PCRE has <a class="reference external" href="https://pcre.sourceforge.net/license.txt">some additional terms</a> that you must agree to in order to use this module.</p>
  202. <p><strong class="examples_text">Example:</strong></p>
  203. <pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">nre</span>
  204. <span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">sugar</span>
  205. <span class="Keyword">let</span> <span class="Identifier">vowels</span> <span class="Operator">=</span> <span class="RawData">re&quot;[aeoui]&quot;</span>
  206. <span class="Keyword">let</span> <span class="Identifier">bounds</span> <span class="Operator">=</span> <span class="Identifier">collect</span><span class="Punctuation">:</span>
  207. <span class="Keyword">for</span> <span class="Identifier">match</span> <span class="Keyword">in</span> <span class="StringLit">&quot;moiga&quot;</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>
  208. <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>
  209. <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>
  210. <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">&quot;moiga&quot;</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>
  211. <span class="Comment"># fully qualified to avoid confusion with nre.toSeq</span>
  212. <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>
  213. <span class="Keyword">let</span> <span class="Identifier">firstVowel</span> <span class="Operator">=</span> <span class="StringLit">&quot;foo&quot;</span><span class="Operator">.</span><span class="Identifier">find</span><span class="Punctuation">(</span><span class="Identifier">vowels</span><span class="Punctuation">)</span>
  214. <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>
  215. <span class="Identifier">assert</span> <span class="Identifier">hasVowel</span>
  216. <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>
  217. <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>
  218. <span class="Comment"># as with module `re`, unless specified otherwise, `start` parameter in each</span>
  219. <span class="Comment"># proc indicates where the scan starts, but outputs are relative to the start</span>
  220. <span class="Comment"># of the input string, not to `start`:</span>
  221. <span class="Identifier">assert</span> <span class="Identifier">find</span><span class="Punctuation">(</span><span class="StringLit">&quot;uxabc&quot;</span><span class="Punctuation">,</span> <span class="RawData">re&quot;(?&lt;=x|y)ab&quot;</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">&quot;ab&quot;</span>
  222. <span class="Identifier">assert</span> <span class="Identifier">find</span><span class="Punctuation">(</span><span class="StringLit">&quot;uxabc&quot;</span><span class="Punctuation">,</span> <span class="RawData">re&quot;ab&quot;</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>
  223. <div class="section" id="6">
  224. <h1><a class="toc-backref" href="#6">Imports</a></h1>
  225. <dl class="item">
  226. <a class="reference external" href="pcre.html">pcre</a>, <a class="reference external" href="util.html">util</a>, <a class="reference external" href="tables.html">tables</a>, <a class="reference external" href="strutils.html">strutils</a>, <a class="reference external" href="options.html">options</a>, <a class="reference external" href="unicode.html">unicode</a>, <a class="reference external" href="assertions.html">assertions</a>
  227. </dl>
  228. </div>
  229. <div class="section" id="7">
  230. <h1><a class="toc-backref" href="#7">Types</a></h1>
  231. <dl class="item">
  232. <div id="CaptureBounds">
  233. <dt><pre><a href="nre.html#CaptureBounds"><span class="Identifier">CaptureBounds</span></a> <span class="Other">=</span> <span class="Keyword">distinct</span> <a href="nre.html#RegexMatch"><span class="Identifier">RegexMatch</span></a></pre></dt>
  234. <dd>
  235. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/nre.nim#L199" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  236. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/nre.nim#L199" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  237. </dd>
  238. </div>
  239. <div id="Captures">
  240. <dt><pre><a href="nre.html#Captures"><span class="Identifier">Captures</span></a> <span class="Other">=</span> <span class="Keyword">distinct</span> <a href="nre.html#RegexMatch"><span class="Identifier">RegexMatch</span></a></pre></dt>
  241. <dd>
  242. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/nre.nim#L198" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  243. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/nre.nim#L198" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  244. </dd>
  245. </div>
  246. <div id="InvalidUnicodeError">
  247. <dt><pre><a href="nre.html#InvalidUnicodeError"><span class="Identifier">InvalidUnicodeError</span></a> <span class="Other">=</span> <span class="Keyword">ref</span> <span class="Keyword">object</span> <span class="Keyword">of</span> <a href="nre.html#RegexError"><span class="Identifier">RegexError</span></a>
  248. <span class="Identifier">pos</span><span class="Operator">*</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> <span class="Comment">## the location of the invalid unicode in bytes</span></pre></dt>
  249. <dd>
  250. Thrown when matching fails due to invalid unicode in strings
  251. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/nre.nim#L206" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  252. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/nre.nim#L206" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  253. </dd>
  254. </div>
  255. <div id="Regex">
  256. <dt><pre><a href="nre.html#Regex"><span class="Identifier">Regex</span></a> <span class="Other">=</span> <span class="Keyword">ref</span> <a href="nre.html#RegexDesc"><span class="Identifier">RegexDesc</span></a></pre></dt>
  257. <dd>
  258. 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&quot;foo&quot;</span></span></tt>, <tt class="docutils literal"><span class="pre"><span class="Identifier">re</span><span class="Punctuation">(</span><span class="RawData">r&quot;(*ANYCRLF)(?x)foo # comment&quot;</span><span class="Operator">.</span></span></tt><dl class="docutils"><dt><tt class="docutils literal"><span class="pre"><span class="Identifier">pattern</span><span class="Punctuation">:</span> <span class="Identifier">string</span></span></tt></dt>
  259. <dd>the string that was used to create the pattern. For details on how to write a pattern, please see <a class="reference external" href="https://www.pcre.org/original/doc/html/pcrepattern.html">the official PCRE pattern documentation.</a></dd>
  260. <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>
  261. <dd>the number of captures that the pattern has.</dd>
  262. <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>
  263. <dd>a table from the capture names to their numeric id.</dd>
  264. </dl>
  265. <h3><a class="toc-backref" id="licencing-options" href="#licencing-options">Options</a></h3><p>The following options may appear anywhere in the pattern, and they affect the rest of it.</p>
  266. <ul class="simple"><li><tt class="docutils literal"><span class="pre"><span class="Punctuation">(</span><span class="Operator">?</span><span class="Identifier">i</span><span class="Punctuation">)</span></span></tt> - case insensitive</li>
  267. <li><tt class="docutils literal"><span class="pre"><span class="Punctuation">(</span><span class="Operator">?</span><span class="Identifier">m</span><span class="Punctuation">)</span></span></tt> - multi-line: <tt class="docutils literal"><span class="pre"><span class="Operator">^</span></span></tt> and <tt class="docutils literal"><span class="pre"><span class="Operator">$</span></span></tt> match the beginning and end of lines, not of the subject string</li>
  268. <li><tt class="docutils literal"><span class="pre"><span class="Punctuation">(</span><span class="Operator">?</span><span class="Identifier">s</span><span class="Punctuation">)</span></span></tt> - <tt class="docutils literal"><span class="pre"><span class="Operator">.</span></span></tt> also matches newline (<em>dotall</em>)</li>
  269. <li><tt class="docutils literal"><span class="pre"><span class="Punctuation">(</span><span class="Operator">?</span><span class="Identifier">U</span><span class="Punctuation">)</span></span></tt> - expressions are not greedy by default. <tt class="docutils literal"><span class="pre"><span class="Operator">?</span></span></tt> can be added to a qualifier to make it greedy</li>
  270. <li><tt class="docutils literal"><span class="pre"><span class="Punctuation">(</span><span class="Operator">?</span><span class="Identifier">x</span><span class="Punctuation">)</span></span></tt> - whitespace and comments (<tt class="docutils literal"><span class="pre"><span class="Comment">#</span></span></tt>) are ignored (<em>extended</em>)</li>
  271. <li><tt class="docutils literal"><span class="pre"><span class="Punctuation">(</span><span class="Operator">?</span><span class="Identifier">X</span><span class="Punctuation">)</span></span></tt> - character escapes without special meaning (<tt class="docutils literal"><span class="pre"><span class="Operator">\</span><span class="Identifier">w</span></span></tt> vs. <tt class="docutils literal"><span class="pre"><span class="Operator">\</span><span class="Identifier">a</span></span></tt>) are errors (<em>extra</em>)</li>
  272. </ul>
  273. <p>One or a combination of these options may appear only at the beginning of the pattern:</p>
  274. <ul class="simple"><li><tt class="docutils literal"><span class="pre"><span class="Punctuation">(</span><span class="Operator">*</span><span class="Identifier">UTF8</span><span class="Punctuation">)</span></span></tt> - treat both the pattern and subject as UTF-8</li>
  275. <li><tt class="docutils literal"><span class="pre"><span class="Punctuation">(</span><span class="Operator">*</span><span class="Identifier">UCP</span><span class="Punctuation">)</span></span></tt> - Unicode character properties; <tt class="docutils literal"><span class="pre"><span class="Operator">\</span><span class="Identifier">w</span></span></tt> matches <tt class="docutils literal"><span class="pre"><span class="Identifier">я</span></span></tt></li>
  276. <li><tt class="docutils literal"><span class="pre"><span class="Punctuation">(</span><span class="Operator">*</span><span class="Identifier">U</span><span class="Punctuation">)</span></span></tt> - a combination of the two options above</li>
  277. <li><tt class="docutils literal"><span class="pre"><span class="Punctuation">(</span><span class="Operator">*</span><span class="Identifier">FIRSTLINE</span><span class="Operator">*</span><span class="Punctuation">)</span></span></tt> - fails if there is not a match on the first line</li>
  278. <li><tt class="docutils literal"><span class="pre"><span class="Punctuation">(</span><span class="Operator">*</span><span class="Identifier">NO_AUTO_CAPTURE</span><span class="Punctuation">)</span></span></tt> - turn off auto-capture for groups; <tt class="docutils literal"><span class="pre"><span class="Punctuation">(</span><span class="Operator">?&lt;</span><span class="Identifier">name</span><span class="Operator">&gt;...</span><span class="Punctuation">)</span></span></tt> can be used to capture</li>
  279. <li><tt class="docutils literal"><span class="pre"><span class="Punctuation">(</span><span class="Operator">*</span><span class="Identifier">CR</span><span class="Punctuation">)</span></span></tt> - newlines are separated by <tt class="docutils literal"><span class="pre"><span class="Operator">\</span><span class="Identifier">r</span></span></tt></li>
  280. <li><tt class="docutils literal"><span class="pre"><span class="Punctuation">(</span><span class="Operator">*</span><span class="Identifier">LF</span><span class="Punctuation">)</span></span></tt> - newlines are separated by <tt class="docutils literal"><span class="pre"><span class="Operator">\</span><span class="Identifier">n</span></span></tt> (UNIX default)</li>
  281. <li><tt class="docutils literal"><span class="pre"><span class="Punctuation">(</span><span class="Operator">*</span><span class="Identifier">CRLF</span><span class="Punctuation">)</span></span></tt> - newlines are separated by <tt class="docutils literal"><span class="pre"><span class="Operator">\</span><span class="Identifier">r</span><span class="Operator">\</span><span class="Identifier">n</span></span></tt> (Windows default)</li>
  282. <li><tt class="docutils literal"><span class="pre"><span class="Punctuation">(</span><span class="Operator">*</span><span class="Identifier">ANYCRLF</span><span class="Punctuation">)</span></span></tt> - newlines are separated by any of the above</li>
  283. <li><p><tt class="docutils literal"><span class="pre"><span class="Punctuation">(</span><span class="Operator">*</span><span class="Identifier">ANY</span><span class="Punctuation">)</span></span></tt> - newlines are separated by any of the above and Unicode newlines:</p>
  284. <p>single characters VT (vertical tab, U+000B), FF (form feed, U+000C), NEL (next line, U+0085), LS (line separator, U+2028), and PS (paragraph separator, U+2029). For the 8-bit library, the last two are recognized only in UTF-8 mode. — man pcre</p>
  285. </li>
  286. <li><tt class="docutils literal"><span class="pre"><span class="Punctuation">(</span><span class="Operator">*</span><span class="Identifier">JAVASCRIPT_COMPAT</span><span class="Punctuation">)</span></span></tt> - JavaScript compatibility</li>
  287. <li><tt class="docutils literal"><span class="pre"><span class="Punctuation">(</span><span class="Operator">*</span><span class="Identifier">NO_STUDY</span><span class="Punctuation">)</span></span></tt> - turn off studying; study is enabled by default</li>
  288. </ul>
  289. <p>For more details on the leading option groups, see the <a class="reference external" href="https://man7.org/linux/man-pages/man3/pcresyntax.3.html#OPTION_SETTING">Option Setting</a> and the <a class="reference external" href="https://man7.org/linux/man-pages/man3/pcresyntax.3.html#NEWLINE_CONVENTION">Newline Convention</a> sections of the <a class="reference external" href="https://man7.org/linux/man-pages/man3/pcresyntax.3.html">PCRE syntax manual</a>.</p>
  290. <p>Some of these options are not part of PCRE and are converted by nre into PCRE flags. These include <tt class="docutils literal"><span class="pre"><span class="Identifier">NEVER_UTF</span></span></tt>, <tt class="docutils literal"><span class="pre"><span class="Identifier">ANCHORED</span></span></tt>, <tt class="docutils literal"><span class="pre"><span class="Identifier">DOLLAR_ENDONLY</span></span></tt>, <tt class="docutils literal"><span class="pre"><span class="Identifier">FIRSTLINE</span></span></tt>, <tt class="docutils literal"><span class="pre"><span class="Identifier">NO_AUTO_CAPTURE</span></span></tt>, <tt class="docutils literal"><span class="pre"><span class="Identifier">JAVASCRIPT_COMPAT</span></span></tt>, <tt class="docutils literal"><span class="pre"><span class="Identifier">U</span></span></tt>, <tt class="docutils literal"><span class="pre"><span class="Identifier">NO_STUDY</span></span></tt>. In other PCRE wrappers, you will need to pass these as separate flags to PCRE.</p>
  291. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/nre.nim#L84" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  292. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/nre.nim#L84" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  293. </dd>
  294. </div>
  295. <div id="RegexDesc">
  296. <dt><pre><a href="nre.html#RegexDesc"><span class="Identifier">RegexDesc</span></a> <span class="Other">=</span> <span class="Keyword">object</span>
  297. <span class="Identifier">pattern</span><span class="Operator">*</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a>
  298. <span class="Comment">## not nil</span>
  299. <span class="Comment">## nil</span></pre></dt>
  300. <dd>
  301. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/nre.nim#L77" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  302. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/nre.nim#L77" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  303. </dd>
  304. </div>
  305. <div id="RegexError">
  306. <dt><pre><a href="nre.html#RegexError"><span class="Identifier">RegexError</span></a> <span class="Other">=</span> <span class="Keyword">ref</span> <span class="Keyword">object</span> <span class="Keyword">of</span> <a href="system.html#CatchableError"><span class="Identifier">CatchableError</span></a></pre></dt>
  307. <dd>
  308. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/nre.nim#L201" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  309. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/nre.nim#L201" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  310. </dd>
  311. </div>
  312. <div id="RegexInternalError">
  313. <dt><pre><a href="nre.html#RegexInternalError"><span class="Identifier">RegexInternalError</span></a> <span class="Other">=</span> <span class="Keyword">ref</span> <span class="Keyword">object</span> <span class="Keyword">of</span> <a href="nre.html#RegexError"><span class="Identifier">RegexError</span></a></pre></dt>
  314. <dd>
  315. Internal error in the module, this probably means that there is a bug
  316. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/nre.nim#L203" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  317. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/nre.nim#L203" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  318. </dd>
  319. </div>
  320. <div id="RegexMatch">
  321. <dt><pre><a href="nre.html#RegexMatch"><span class="Identifier">RegexMatch</span></a> <span class="Other">=</span> <span class="Keyword">object</span>
  322. <span class="Identifier">pattern</span><span class="Operator">*</span><span class="Other">:</span> <a href="nre.html#Regex"><span class="Identifier">Regex</span></a> <span class="Comment">## The regex doing the matching.</span>
  323. <span class="Comment">## Not nil.</span>
  324. <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>
  325. <span class="Comment">## First item is the bounds of the match</span>
  326. <span class="Comment">## Other items are the captures</span>
  327. <span class="Comment">## `a` is inclusive start, `b` is exclusive end</span></pre></dt>
  328. <dd>
  329. Usually seen as Option<a class="reference internal nimdoc" title="object RegexMatch" href="#RegexMatch">RegexMatch</a>, 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">pattern</span><span class="Punctuation">:</span> <span class="Identifier">Regex</span></span></tt></dt>
  330. <dd>the pattern that is being matched</dd>
  331. <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>
  332. <dd>the string that was matched against</dd>
  333. <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>
  334. <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>
  335. <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>
  336. <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>
  337. <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>
  338. <dd>the full text of the match.</dd>
  339. <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>
  340. <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>
  341. <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>
  342. <dd>returns a table with each named capture as a key.</dd>
  343. <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>
  344. <dd>returns all the captures by their number.</dd>
  345. <dt><tt class="docutils literal"><span class="pre"><span class="Operator">$:</span> <span class="Identifier">string</span></span></tt></dt>
  346. <dd>same as <tt class="docutils literal"><span class="pre"><span class="Identifier">match</span></span></tt></dd>
  347. </dl>
  348. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/nre.nim#L156" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  349. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/nre.nim#L156" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  350. </dd>
  351. </div>
  352. <div id="StudyError">
  353. <dt><pre><a href="nre.html#StudyError"><span class="Identifier">StudyError</span></a> <span class="Other">=</span> <span class="Keyword">ref</span> <span class="Keyword">object</span> <span class="Keyword">of</span> <a href="nre.html#RegexError"><span class="Identifier">RegexError</span></a></pre></dt>
  354. <dd>
  355. Thrown when studying the regular expression fails for whatever reason. The message contains the error code.
  356. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/nre.nim#L216" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  357. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/nre.nim#L216" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  358. </dd>
  359. </div>
  360. <div id="SyntaxError">
  361. <dt><pre><a href="nre.html#SyntaxError"><span class="Identifier">SyntaxError</span></a> <span class="Other">=</span> <span class="Keyword">ref</span> <span class="Keyword">object</span> <span class="Keyword">of</span> <a href="nre.html#RegexError"><span class="Identifier">RegexError</span></a>
  362. <span class="Identifier">pos</span><span class="Operator">*</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> <span class="Comment">## the location of the syntax error in bytes</span>
  363. <span class="Identifier">pattern</span><span class="Operator">*</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> <span class="Comment">## the pattern that caused the problem</span></pre></dt>
  364. <dd>
  365. Thrown when there is a syntax error in the regular expression string passed in
  366. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/nre.nim#L210" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  367. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/nre.nim#L210" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  368. </dd>
  369. </div>
  370. </dl>
  371. </div>
  372. <div class="section" id="12">
  373. <h1><a class="toc-backref" href="#12">Procs</a></h1>
  374. <dl class="item">
  375. <div id="$-procs-all">
  376. <div id="$,RegexMatch">
  377. <dt><pre><span class="Keyword">proc</span> <a href="#%24%2CRegexMatch"><span class="Identifier">`$`</span></a><span class="Other">(</span><span class="Identifier">pattern</span><span class="Other">:</span> <a href="nre.html#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>
  378. <dd>
  379. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/nre.nim#L429" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  380. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/nre.nim#L429" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  381. </dd>
  382. </div>
  383. </div>
  384. <div id="==-procs-all">
  385. <div id="==,Regex,Regex">
  386. <dt><pre><span class="Keyword">proc</span> <a href="#%3D%3D%2CRegex%2CRegex"><span class="Identifier">`==`</span></a><span class="Other">(</span><span class="Identifier">a</span><span class="Other">,</span> <span class="Identifier">b</span><span class="Other">:</span> <a href="nre.html#Regex"><span class="Identifier">Regex</span></a><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="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>
  387. <dd>
  388. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/nre.nim#L432" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  389. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/nre.nim#L432" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  390. </dd>
  391. </div>
  392. <div id="==,RegexMatch,RegexMatch">
  393. <dt><pre><span class="Keyword">proc</span> <a href="#%3D%3D%2CRegexMatch%2CRegexMatch"><span class="Identifier">`==`</span></a><span class="Other">(</span><span class="Identifier">a</span><span class="Other">,</span> <span class="Identifier">b</span><span class="Other">:</span> <a href="nre.html#RegexMatch"><span class="Identifier">RegexMatch</span></a><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="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>
  394. <dd>
  395. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/nre.nim#L440" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  396. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/nre.nim#L440" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  397. </dd>
  398. </div>
  399. </div>
  400. <div id="[]-procs-all">
  401. <div id="[],CaptureBounds,int">
  402. <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">pattern</span><span class="Other">:</span> <a href="nre.html#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><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>
  403. <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>
  404. <dd>
  405. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/nre.nim#L341" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  406. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/nre.nim#L341" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  407. </dd>
  408. </div>
  409. <div id="[],CaptureBounds,string">
  410. <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">pattern</span><span class="Other">:</span> <a href="nre.html#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> {.
  411. <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>
  412. <dd>
  413. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/nre.nim#L375" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  414. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/nre.nim#L375" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  415. </dd>
  416. </div>
  417. <div id="[],Captures,int">
  418. <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">pattern</span><span class="Other">:</span> <a href="nre.html#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><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>
  419. <dd>
  420. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/nre.nim#L349" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  421. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/nre.nim#L349" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  422. </dd>
  423. </div>
  424. <div id="[],Captures,string">
  425. <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">pattern</span><span class="Other">:</span> <a href="nre.html#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><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>
  426. <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>
  427. <dd>
  428. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/nre.nim#L381" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  429. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/nre.nim#L381" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  430. </dd>
  431. </div>
  432. </div>
  433. <div id="captureBounds-procs-all">
  434. <div id="captureBounds,RegexMatch">
  435. <dt><pre><span class="Keyword">func</span> <a href="#captureBounds%2CRegexMatch"><span class="Identifier">captureBounds</span></a><span class="Other">(</span><span class="Identifier">pattern</span><span class="Other">:</span> <a href="nre.html#RegexMatch"><span class="Identifier">RegexMatch</span></a><span class="Other">)</span><span class="Other">:</span> <a href="nre.html#CaptureBounds"><span class="Identifier">CaptureBounds</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>
  436. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  437. <dd>
  438. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/nre.nim#L330" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  439. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/nre.nim#L330" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  440. </dd>
  441. </div>
  442. </div>
  443. <div id="captureCount-procs-all">
  444. <div id="captureCount,Regex">
  445. <dt><pre><span class="Keyword">proc</span> <a href="#captureCount%2CRegex"><span class="Identifier">captureCount</span></a><span class="Other">(</span><span class="Identifier">pattern</span><span class="Other">:</span> <a href="nre.html#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><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="Other">]</span><span class="Other">,</span>
  446. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  447. <dd>
  448. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/nre.nim#L302" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  449. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/nre.nim#L302" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  450. </dd>
  451. </div>
  452. </div>
  453. <div id="captureNameId-procs-all">
  454. <div id="captureNameId,Regex">
  455. <dt><pre><span class="Keyword">proc</span> <a href="#captureNameId%2CRegex"><span class="Identifier">captureNameId</span></a><span class="Other">(</span><span class="Identifier">pattern</span><span class="Other">:</span> <a href="nre.html#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>
  456. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  457. <dd>
  458. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/nre.nim#L305" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  459. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/nre.nim#L305" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  460. </dd>
  461. </div>
  462. </div>
  463. <div id="captures-procs-all">
  464. <div id="captures,RegexMatch">
  465. <dt><pre><span class="Keyword">func</span> <a href="#captures%2CRegexMatch"><span class="Identifier">captures</span></a><span class="Other">(</span><span class="Identifier">pattern</span><span class="Other">:</span> <a href="nre.html#RegexMatch"><span class="Identifier">RegexMatch</span></a><span class="Other">)</span><span class="Other">:</span> <a href="nre.html#Captures"><span class="Identifier">Captures</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>
  466. <dd>
  467. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/nre.nim#L332" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  468. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/nre.nim#L332" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  469. </dd>
  470. </div>
  471. </div>
  472. <div id="contains-procs-all">
  473. <div id="contains,CaptureBounds,int">
  474. <dt><pre><span class="Keyword">func</span> <a href="#contains%2CCaptureBounds%2Cint"><span class="Identifier">contains</span></a><span class="Other">(</span><span class="Identifier">pattern</span><span class="Other">:</span> <a href="nre.html#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><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>
  475. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  476. <dd>
  477. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/nre.nim#L334" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  478. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/nre.nim#L334" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  479. </dd>
  480. </div>
  481. <div id="contains,CaptureBounds,string">
  482. <dt><pre><span class="Keyword">func</span> <a href="#contains%2CCaptureBounds%2Cstring"><span class="Identifier">contains</span></a><span class="Other">(</span><span class="Identifier">pattern</span><span class="Other">:</span> <a href="nre.html#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#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="Identifier">KeyError</span><span class="Other">]</span><span class="Other">,</span>
  483. <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>
  484. <dd>
  485. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/nre.nim#L361" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  486. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/nre.nim#L361" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  487. </dd>
  488. </div>
  489. <div id="contains,Captures,int">
  490. <dt><pre><span class="Keyword">func</span> <a href="#contains%2CCaptures%2Cint"><span class="Identifier">contains</span></a><span class="Other">(</span><span class="Identifier">pattern</span><span class="Other">:</span> <a href="nre.html#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#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="Other">]</span><span class="Other">,</span>
  491. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  492. <dd>
  493. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/nre.nim#L338" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  494. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/nre.nim#L338" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  495. </dd>
  496. </div>
  497. <div id="contains,Captures,string">
  498. <dt><pre><span class="Keyword">func</span> <a href="#contains%2CCaptures%2Cstring"><span class="Identifier">contains</span></a><span class="Other">(</span><span class="Identifier">pattern</span><span class="Other">:</span> <a href="nre.html#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><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>
  499. <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>
  500. <dd>
  501. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/nre.nim#L368" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  502. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/nre.nim#L368" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  503. </dd>
  504. </div>
  505. <div id="contains,string,Regex,int">
  506. <dt><pre><span class="Keyword">proc</span> <a href="#contains%2Cstring%2CRegex%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="nre.html#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> {.
  507. <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="Identifier">RegexInternalError</span><span class="Other">,</span> <span class="Identifier">InvalidUnicodeError</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>
  508. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  509. <dd>
  510. 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>.
  511. <p><strong class="examples_text">Example:</strong></p>
  512. <pre class="listing"><span class="Identifier">assert</span> <span class="StringLit">&quot;abc&quot;</span><span class="Operator">.</span><span class="Identifier">contains</span><span class="Punctuation">(</span><span class="RawData">re&quot;bc&quot;</span><span class="Punctuation">)</span>
  513. <span class="Identifier">assert</span> <span class="Keyword">not</span> <span class="StringLit">&quot;abc&quot;</span><span class="Operator">.</span><span class="Identifier">contains</span><span class="Punctuation">(</span><span class="RawData">re&quot;cd&quot;</span><span class="Punctuation">)</span>
  514. <span class="Identifier">assert</span> <span class="Keyword">not</span> <span class="StringLit">&quot;abc&quot;</span><span class="Operator">.</span><span class="Identifier">contains</span><span class="Punctuation">(</span><span class="RawData">re&quot;a&quot;</span><span class="Punctuation">,</span> <span class="Identifier">start</span> <span class="Operator">=</span> <span class="DecNumber">1</span><span class="Punctuation">)</span></pre>
  515. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/nre.nim#L628" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  516. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/nre.nim#L628" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  517. </dd>
  518. </div>
  519. </div>
  520. <div id="escapeRe-procs-all">
  521. <div id="escapeRe,string">
  522. <dt><pre><span class="Keyword">proc</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">gcsafe</span><span class="Other">,</span> <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>
  523. <dd>
  524. <p>Escapes the string so it doesn't match any special characters. Incompatible with the Extra flag (<tt class="docutils literal"><span class="pre"><span class="Identifier">X</span></span></tt>).</p>
  525. <p>Escaped char: <tt class="docutils literal"><span class="pre"><span class="Operator">\</span> <span class="Operator">+</span> <span class="Operator">*</span> <span class="Operator">?</span> <span class="Punctuation">[</span> <span class="Operator">^</span> <span class="Punctuation">]</span> <span class="Operator">$</span> <span class="Punctuation">(</span> <span class="Punctuation">)</span> <span class="Punctuation">{</span> <span class="Punctuation">}</span> <span class="Operator">=</span> <span class="Operator">!</span> <span class="Operator">&lt;</span> <span class="Operator">&gt;</span> <span class="Operator">|</span> <span class="Punctuation">:</span> <span class="Operator">-</span></span></tt></p>
  526. <p><strong class="examples_text">Example:</strong></p>
  527. <pre class="listing"><span class="Identifier">assert</span> <span class="Identifier">escapeRe</span><span class="Punctuation">(</span><span class="StringLit">&quot;fly+wind&quot;</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;fly</span><span class="EscapeSequence">\\</span><span class="StringLit">+wind&quot;</span>
  528. <span class="Identifier">assert</span> <span class="Identifier">escapeRe</span><span class="Punctuation">(</span><span class="StringLit">&quot;!&quot;</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;</span><span class="EscapeSequence">\\</span><span class="StringLit">!&quot;</span>
  529. <span class="Identifier">assert</span> <span class="Identifier">escapeRe</span><span class="Punctuation">(</span><span class="StringLit">&quot;nim*&quot;</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;nim</span><span class="EscapeSequence">\\</span><span class="StringLit">*&quot;</span></pre>
  530. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/nre.nim#L752" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  531. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/nre.nim#L752" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  532. </dd>
  533. </div>
  534. </div>
  535. <div id="find-procs-all">
  536. <div id="find,string,Regex,int">
  537. <dt><pre><span class="Keyword">proc</span> <a href="#find%2Cstring%2CRegex%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="nre.html#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>
  538. <a href="nre.html#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="Identifier">ValueError</span><span class="Other">,</span> <span class="Identifier">RegexInternalError</span><span class="Other">,</span> <span class="Identifier">InvalidUnicodeError</span><span class="Other">]</span><span class="Other">,</span>
  539. <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>
  540. <dd>
  541. 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>
  542. <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>
  543. <dt><tt class="docutils literal"><span class="pre"><span class="Identifier">endpos</span></span></tt></dt>
  544. <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>
  545. </dl>
  546. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/nre.nim#L610" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  547. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/nre.nim#L610" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  548. </dd>
  549. </div>
  550. </div>
  551. <div id="findAll-procs-all">
  552. <div id="findAll,string,Regex,int">
  553. <dt><pre><span class="Keyword">proc</span> <a href="#findAll%2Cstring%2CRegex%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="nre.html#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>
  554. <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="Identifier">ValueError</span><span class="Other">,</span> <span class="Identifier">RegexInternalError</span><span class="Other">,</span> <span class="Identifier">InvalidUnicodeError</span><span class="Other">]</span><span class="Other">,</span>
  555. <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>
  556. <dd>
  557. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/nre.nim#L623" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  558. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/nre.nim#L623" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  559. </dd>
  560. </div>
  561. </div>
  562. <div id="match-procs-all">
  563. <div id="match,RegexMatch">
  564. <dt><pre><span class="Keyword">func</span> <a href="#match%2CRegexMatch"><span class="Identifier">match</span></a><span class="Other">(</span><span class="Identifier">pattern</span><span class="Other">:</span> <a href="nre.html#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>
  565. <dd>
  566. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/nre.nim#L355" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  567. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/nre.nim#L355" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  568. </dd>
  569. </div>
  570. <div id="match,string,Regex,int">
  571. <dt><pre><span class="Keyword">proc</span> <a href="#match%2Cstring%2CRegex%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="nre.html#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>
  572. <a href="nre.html#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="Identifier">ValueError</span><span class="Other">,</span> <span class="Identifier">RegexInternalError</span><span class="Other">,</span> <span class="Identifier">InvalidUnicodeError</span><span class="Other">]</span><span class="Other">,</span>
  573. <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>
  574. <dd>
  575. Like <a class="reference external" href="#find,string,Regex,int">find(...)</a>, but anchored to the start of the string.
  576. <p><strong class="examples_text">Example:</strong></p>
  577. <pre class="listing"><span class="Identifier">assert</span> <span class="StringLit">&quot;foo&quot;</span><span class="Operator">.</span><span class="Identifier">match</span><span class="Punctuation">(</span><span class="RawData">re&quot;f&quot;</span><span class="Punctuation">)</span><span class="Operator">.</span><span class="Identifier">isSome</span>
  578. <span class="Identifier">assert</span> <span class="StringLit">&quot;foo&quot;</span><span class="Operator">.</span><span class="Identifier">match</span><span class="Punctuation">(</span><span class="RawData">re&quot;o&quot;</span><span class="Punctuation">)</span><span class="Operator">.</span><span class="Identifier">isNone</span>
  579. <span class="Identifier">assert</span> <span class="StringLit">&quot;abc&quot;</span><span class="Operator">.</span><span class="Identifier">match</span><span class="Punctuation">(</span><span class="RawData">re&quot;(\w)&quot;</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">&quot;a&quot;</span>
  580. <span class="Identifier">assert</span> <span class="StringLit">&quot;abc&quot;</span><span class="Operator">.</span><span class="Identifier">match</span><span class="Punctuation">(</span><span class="RawData">re&quot;(?&lt;letter&gt;\w)&quot;</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">&quot;letter&quot;</span><span class="Punctuation">]</span> <span class="Operator">==</span> <span class="StringLit">&quot;a&quot;</span>
  581. <span class="Identifier">assert</span> <span class="StringLit">&quot;abc&quot;</span><span class="Operator">.</span><span class="Identifier">match</span><span class="Punctuation">(</span><span class="RawData">re&quot;(\w)\w&quot;</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">&quot;ab&quot;</span>
  582. <span class="Identifier">assert</span> <span class="StringLit">&quot;abc&quot;</span><span class="Operator">.</span><span class="Identifier">match</span><span class="Punctuation">(</span><span class="RawData">re&quot;(\w)&quot;</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>
  583. <span class="Identifier">assert</span> <span class="DecNumber">0</span> <span class="Keyword">in</span> <span class="StringLit">&quot;abc&quot;</span><span class="Operator">.</span><span class="Identifier">match</span><span class="Punctuation">(</span><span class="RawData">re&quot;(\w)&quot;</span><span class="Punctuation">)</span><span class="Operator">.</span><span class="Identifier">get</span><span class="Operator">.</span><span class="Identifier">captureBounds</span>
  584. <span class="Identifier">assert</span> <span class="StringLit">&quot;abc&quot;</span><span class="Operator">.</span><span class="Identifier">match</span><span class="Punctuation">(</span><span class="RawData">re&quot;&quot;</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>
  585. <span class="Identifier">assert</span> <span class="StringLit">&quot;abc&quot;</span><span class="Operator">.</span><span class="Identifier">match</span><span class="Punctuation">(</span><span class="RawData">re&quot;abc&quot;</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>
  586. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/nre.nim#L542" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  587. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/nre.nim#L542" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  588. </dd>
  589. </div>
  590. </div>
  591. <div id="matchBounds-procs-all">
  592. <div id="matchBounds,RegexMatch">
  593. <dt><pre><span class="Keyword">func</span> <a href="#matchBounds%2CRegexMatch"><span class="Identifier">matchBounds</span></a><span class="Other">(</span><span class="Identifier">pattern</span><span class="Other">:</span> <a href="nre.html#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><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>
  594. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  595. <dd>
  596. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/nre.nim#L358" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  597. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/nre.nim#L358" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  598. </dd>
  599. </div>
  600. </div>
  601. <div id="re-procs-all">
  602. <div id="re,string">
  603. <dt><pre><span class="Keyword">proc</span> <a href="#re%2Cstring"><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="Other">:</span> <a href="nre.html#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">KeyError</span><span class="Other">,</span> <span class="Identifier">SyntaxError</span><span class="Other">,</span> <span class="Identifier">StudyError</span><span class="Other">,</span>
  604. <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="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>
  605. <dd>
  606. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/nre.nim#L499" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  607. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/nre.nim#L499" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  608. </dd>
  609. </div>
  610. </div>
  611. <div id="replace-procs-all">
  612. <div id="replace,string,Regex,string">
  613. <dt><pre><span class="Keyword">proc</span> <a href="#replace%2Cstring%2CRegex%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="nre.html#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> {.
  614. <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="Identifier">RegexInternalError</span><span class="Other">,</span> <span class="Identifier">InvalidUnicodeError</span><span class="Other">,</span> <span class="Identifier">KeyError</span><span class="Other">]</span><span class="Other">,</span>
  615. <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>
  616. <dd>
  617. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/nre.nim#L747" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  618. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/nre.nim#L747" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  619. </dd>
  620. </div>
  621. <div id="replace,string,Regex,proc(RegexMatch)">
  622. <dt><pre><span class="Keyword">proc</span> <a href="#replace%2Cstring%2CRegex%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="nre.html#Regex"><span class="Identifier">Regex</span></a><span class="Other">;</span>
  623. <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="nre.html#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> {.
  624. <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="Identifier">RegexInternalError</span><span class="Other">,</span> <span class="Identifier">InvalidUnicodeError</span><span class="Other">,</span> <span class="Identifier">Exception</span><span class="Other">]</span><span class="Other">,</span>
  625. <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>
  626. <dd>
  627. <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>
  628. <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>
  629. <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>
  630. <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>
  631. <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>
  632. <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>
  633. <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>
  634. <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>
  635. <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>
  636. <li><tt class="docutils literal"><span class="pre"><span class="Operator">$</span><span class="Comment">#</span></span></tt> - first capture</li>
  637. <li><tt class="docutils literal"><span class="pre"><span class="Operator">$</span><span class="DecNumber">0</span></span></tt> - full match</li>
  638. </ul>
  639. <p>If a given capture is missing, <tt class="docutils literal"><span class="pre"><span class="Identifier">IndexDefect</span></span></tt> thrown for un-named captures and <tt class="docutils literal"><span class="pre"><span class="Identifier">KeyError</span></span></tt> for named captures.</p>
  640. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/nre.nim#L718" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  641. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/nre.nim#L718" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  642. </dd>
  643. </div>
  644. <div id="replace,string,Regex,proc(string)">
  645. <dt><pre><span class="Keyword">proc</span> <a href="#replace%2Cstring%2CRegex%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="nre.html#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> {.
  646. <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="Identifier">RegexInternalError</span><span class="Other">,</span> <span class="Identifier">InvalidUnicodeError</span><span class="Other">,</span> <span class="Identifier">Exception</span><span class="Other">]</span><span class="Other">,</span>
  647. <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>
  648. <dd>
  649. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/nre.nim#L743" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  650. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/nre.nim#L743" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  651. </dd>
  652. </div>
  653. </div>
  654. <div id="split-procs-all">
  655. <div id="split,string,Regex,int,int">
  656. <dt><pre><span class="Keyword">proc</span> <a href="#split%2Cstring%2CRegex%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="nre.html#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> {.
  657. <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="Identifier">RegexInternalError</span><span class="Other">,</span> <span class="Identifier">InvalidUnicodeError</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>
  658. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  659. <dd>
  660. <p>Splits the string with the given regex. This works according to the rules that Perl and Javascript use.</p>
  661. <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>
  662. <p><strong class="examples_text">Example:</strong></p>
  663. <pre class="listing"><span class="Comment"># - If the match is zero-width, then the string is still split:</span>
  664. <span class="Identifier">assert</span> <span class="StringLit">&quot;123&quot;</span><span class="Operator">.</span><span class="Identifier">split</span><span class="Punctuation">(</span><span class="RawData">re&quot;&quot;</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="Operator">@</span><span class="Punctuation">[</span><span class="StringLit">&quot;1&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;2&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;3&quot;</span><span class="Punctuation">]</span>
  665. <span class="Comment"># - If the pattern has a capture in it, it is added after the string</span>
  666. <span class="Comment"># split:</span>
  667. <span class="Identifier">assert</span> <span class="StringLit">&quot;12&quot;</span><span class="Operator">.</span><span class="Identifier">split</span><span class="Punctuation">(</span><span class="RawData">re&quot;(\d)&quot;</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="Operator">@</span><span class="Punctuation">[</span><span class="StringLit">&quot;&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;1&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;2&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;&quot;</span><span class="Punctuation">]</span>
  668. <span class="Comment"># - If `maxsplit != -1`, then the string will only be split</span>
  669. <span class="Comment"># `maxsplit - 1` times. This means that there will be `maxsplit`</span>
  670. <span class="Comment"># strings in the output seq.</span>
  671. <span class="Identifier">assert</span> <span class="StringLit">&quot;1.2.3&quot;</span><span class="Operator">.</span><span class="Identifier">split</span><span class="Punctuation">(</span><span class="RawData">re&quot;\.&quot;</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">&quot;1&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;2.3&quot;</span><span class="Punctuation">]</span></pre>
  672. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/nre.nim#L639" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  673. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/nre.nim#L639" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  674. </dd>
  675. </div>
  676. </div>
  677. <div id="toSeq-procs-all">
  678. <div id="toSeq,CaptureBounds">
  679. <dt><pre><span class="Keyword">proc</span> <a href="#toSeq%2CCaptureBounds"><span class="Identifier">toSeq</span></a><span class="Other">(</span><span class="Identifier">pattern</span><span class="Other">:</span> <a href="nre.html#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>
  680. <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="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="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>
  681. <dd>
  682. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/nre.nim#L419" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  683. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/nre.nim#L419" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  684. </dd>
  685. </div>
  686. <div id="toSeq,Captures,Option[string]">
  687. <dt><pre><span class="Keyword">proc</span> <a href="#toSeq%2CCaptures%2COption%5Bstring%5D"><span class="Identifier">toSeq</span></a><span class="Other">(</span><span class="Identifier">pattern</span><span class="Other">:</span> <a href="nre.html#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>
  688. <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="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="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>
  689. <dd>
  690. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/nre.nim#L424" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  691. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/nre.nim#L424" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  692. </dd>
  693. </div>
  694. </div>
  695. <div id="toTable-procs-all">
  696. <div id="toTable,CaptureBounds">
  697. <dt><pre><span class="Keyword">func</span> <a href="#toTable%2CCaptureBounds"><span class="Identifier">toTable</span></a><span class="Other">(</span><span class="Identifier">pattern</span><span class="Other">:</span> <a href="nre.html#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> {.
  698. <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>
  699. <dd>
  700. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/nre.nim#L396" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  701. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/nre.nim#L396" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  702. </dd>
  703. </div>
  704. <div id="toTable,Captures">
  705. <dt><pre><span class="Keyword">func</span> <a href="#toTable%2CCaptures"><span class="Identifier">toTable</span></a><span class="Other">(</span><span class="Identifier">pattern</span><span class="Other">:</span> <a href="nre.html#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="Identifier">KeyError</span><span class="Other">]</span><span class="Other">,</span>
  706. <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>
  707. <dd>
  708. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/nre.nim#L392" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  709. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/nre.nim#L392" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  710. </dd>
  711. </div>
  712. </div>
  713. </dl>
  714. </div>
  715. <div class="section" id="15">
  716. <h1><a class="toc-backref" href="#15">Iterators</a></h1>
  717. <dl class="item">
  718. <div id="findIter-iterators-all">
  719. <div id="findIter.i,string,Regex,int">
  720. <dt><pre><span class="Keyword">iterator</span> <a href="#findIter.i%2Cstring%2CRegex%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="nre.html#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="nre.html#RegexMatch"><span class="Identifier">RegexMatch</span></a> {.
  721. <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="Identifier">RegexInternalError</span><span class="Other">,</span> <span class="Identifier">InvalidUnicodeError</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>
  722. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  723. <dd>
  724. Works the same as <a class="reference external" href="#find,string,Regex,int">find(...)</a>, but finds every non-overlapping match:
  725. <p><strong class="examples_text">Example:</strong></p>
  726. <pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">sugar</span>
  727. <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">&quot;2222&quot;</span><span class="Operator">.</span><span class="Identifier">findIter</span><span class="Punctuation">(</span><span class="RawData">re&quot;22&quot;</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">&quot;22&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;22&quot;</span><span class="Punctuation">]</span>
  728. <span class="Comment"># not @[&quot;22&quot;, &quot;22&quot;, &quot;22&quot;]</span></pre><p>Arguments are the same as <a class="reference external" href="#find,string,Regex,int">find(...)</a></p>
  729. <p>Variants:</p>
  730. <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>
  731. </ul>
  732. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/nre.nim#L559" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  733. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/nre.nim#L559" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  734. </dd>
  735. </div>
  736. </div>
  737. <div id="items-iterators-all">
  738. <div id="items.i,CaptureBounds">
  739. <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">pattern</span><span class="Other">:</span> <a href="nre.html#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>
  740. <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="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="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>
  741. <dd>
  742. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/nre.nim#L411" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  743. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/nre.nim#L411" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  744. </dd>
  745. </div>
  746. <div id="items.i,Captures,Option[string]">
  747. <dt><pre><span class="Keyword">iterator</span> <a href="#items.i%2CCaptures%2COption%5Bstring%5D"><span class="Identifier">items</span></a><span class="Other">(</span><span class="Identifier">pattern</span><span class="Other">:</span> <a href="nre.html#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="options.html#Option"><span class="Identifier">Option</span></a><span class="Other">[</span>
  748. <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="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="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>
  749. <dd>
  750. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/nre.nim#L415" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  751. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/nre.nim#L415" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  752. </dd>
  753. </div>
  754. </div>
  755. </dl>
  756. </div>
  757. </div>
  758. </div>
  759. <div class="twelve-columns footer">
  760. <span class="nim-sprite"></span>
  761. <br>
  762. <small style="color: var(--hint);">Made with Nim. Generated: 2024-12-25 13:28:31 UTC</small>
  763. </div>
  764. </div>
  765. </div>
  766. <script defer data-domain="nim-lang.org" src="https://plausible.io/js/plausible.js"></script>
  767. </body>
  768. </html>