re.html 144 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980
  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/re</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/re</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. <li><a class="reference" id="licence-of-the-pcre-library_toc" href="#licence-of-the-pcre-library">Licence of the PCRE library</a></li>
  50. <li><a class="reference" id="regular-expression-syntax-and-semantics_toc" href="#regular-expression-syntax-and-semantics">Regular expression syntax and semantics</a></li>
  51. <ul class="simple"><li><a class="reference" id="regular-expression-syntax-and-semantics-backslash_toc" href="#regular-expression-syntax-and-semantics-backslash">Backslash</a></li>
  52. <li><a class="reference" id="regular-expression-syntax-and-semantics-nonminusprinting-characters_toc" href="#regular-expression-syntax-and-semantics-nonminusprinting-characters">Non-printing characters</a></li>
  53. <li><a class="reference" id="regular-expression-syntax-and-semantics-generic-character-types_toc" href="#regular-expression-syntax-and-semantics-generic-character-types">Generic character types</a></li>
  54. <li><a class="reference" id="regular-expression-syntax-and-semantics-simple-assertions_toc" href="#regular-expression-syntax-and-semantics-simple-assertions">Simple assertions</a></li>
  55. </ul><li>
  56. <a class="reference reference-toplevel" href="#6" id="56">Imports</a>
  57. </li>
  58. <li>
  59. <details open>
  60. <summary><a class="reference reference-toplevel" href="#7" id="57">Types</a></summary>
  61. <ul class="simple simple-toc-section">
  62. <li><a class="reference" href="#Regex" title="Regex = ref RegexDesc">Regex</a></li>
  63. <li><a class="reference" href="#RegexError" title="RegexError = object of ValueError">RegexError</a></li>
  64. <li><a class="reference" href="#RegexFlag" title="RegexFlag = enum
  65. reIgnoreCase = 0, ## do caseless matching
  66. reMultiLine = 1, ## `^` and `$` match newlines within data
  67. reDotAll = 2, ## `.` matches anything including NL
  68. reExtended = 3, ## ignore whitespace and `#` comments
  69. reStudy = 4 ## study the expression (may be omitted if the
  70. ## expression will be used only once)">RegexFlag</a></li>
  71. </ul>
  72. </details>
  73. </li>
  74. <li>
  75. <details open>
  76. <summary><a class="reference reference-toplevel" href="#10" id="60">Consts</a></summary>
  77. <ul class="simple simple-toc-section">
  78. <li><a class="reference" href="#MaxReBufSize" title="MaxReBufSize = 2147483647'i32">MaxReBufSize</a></li>
  79. <li><a class="reference" href="#MaxSubpatterns" title="MaxSubpatterns = 20">MaxSubpatterns</a></li>
  80. </ul>
  81. </details>
  82. </li>
  83. <li>
  84. <details open>
  85. <summary><a class="reference reference-toplevel" href="#12" id="62">Procs</a></summary>
  86. <ul class="simple simple-toc-section">
  87. <ul class="simple nested-toc-section">contains
  88. <li><a class="reference" href="#contains%2Cstring%2CRegex%2CopenArray%5Bstring%5D%2Cint" title="contains(s: string; pattern: Regex; matches: var openArray[string]; start = 0): bool">contains(s: string; pattern: Regex; matches: var openArray[string]; start = 0): bool</a></li>
  89. <li><a class="reference" href="#contains%2Cstring%2CRegex%2Cint" title="contains(s: string; pattern: Regex; start = 0): bool">contains(s: string; pattern: Regex; start = 0): bool</a></li>
  90. </ul>
  91. <ul class="simple nested-toc-section">endsWith
  92. <li><a class="reference" href="#endsWith%2Cstring%2CRegex" title="endsWith(s: string; suffix: Regex): bool">endsWith(s: string; suffix: Regex): bool</a></li>
  93. </ul>
  94. <ul class="simple nested-toc-section">escapeRe
  95. <li><a class="reference" href="#escapeRe%2Cstring" title="escapeRe(s: string): string">escapeRe(s: string): string</a></li>
  96. </ul>
  97. <ul class="simple nested-toc-section">find
  98. <li><a class="reference" href="#find%2Ccstring%2CRegex%2CopenArray%5Bstring%5D%2Cint%2Cint" title="find(buf: cstring; pattern: Regex; matches: var openArray[string]; start = 0;
  99. bufSize: int): int">find(buf: cstring; pattern: Regex; matches: var openArray[string]; start = 0;
  100. bufSize: int): int</a></li>
  101. <li><a class="reference" href="#find%2Ccstring%2CRegex%2Cint%2Cint" title="find(buf: cstring; pattern: Regex; start = 0; bufSize: int): int">find(buf: cstring; pattern: Regex; start = 0; bufSize: int): int</a></li>
  102. <li><a class="reference" href="#find%2Cstring%2CRegex%2CopenArray%5Bstring%5D%2Cint" title="find(s: string; pattern: Regex; matches: var openArray[string]; start = 0): int">find(s: string; pattern: Regex; matches: var openArray[string]; start = 0): int</a></li>
  103. <li><a class="reference" href="#find%2Cstring%2CRegex%2Cint" title="find(s: string; pattern: Regex; start = 0): int">find(s: string; pattern: Regex; start = 0): int</a></li>
  104. </ul>
  105. <ul class="simple nested-toc-section">findAll
  106. <li><a class="reference" href="#findAll%2Cstring%2CRegex%2Cint" title="findAll(s: string; pattern: Regex; start = 0): seq[string]">findAll(s: string; pattern: Regex; start = 0): seq[string]</a></li>
  107. </ul>
  108. <ul class="simple nested-toc-section">findBounds
  109. <li><a class="reference" href="#findBounds%2Ccstring%2CRegex%2CopenArray%5Btuple%5Bint%2Cint%5D%5D%2Cint%2Cint" title="findBounds(buf: cstring; pattern: Regex;
  110. matches: var openArray[tuple[first, last: int]]; start = 0;
  111. bufSize: int): tuple[first, last: int]">findBounds(buf: cstring; pattern: Regex;
  112. matches: var openArray[tuple[first, last: int]]; start = 0;
  113. bufSize: int): tuple[first, last: int]</a></li>
  114. <li><a class="reference" href="#findBounds%2Ccstring%2CRegex%2CopenArray%5Bstring%5D%2Cint%2Cint" title="findBounds(buf: cstring; pattern: Regex; matches: var openArray[string];
  115. start = 0; bufSize: int): tuple[first, last: int]">findBounds(buf: cstring; pattern: Regex; matches: var openArray[string];
  116. start = 0; bufSize: int): tuple[first, last: int]</a></li>
  117. <li><a class="reference" href="#findBounds%2Ccstring%2CRegex%2Cint%2Cint" title="findBounds(buf: cstring; pattern: Regex; start = 0; bufSize: int): tuple[
  118. first, last: int]">findBounds(buf: cstring; pattern: Regex; start = 0; bufSize: int): tuple[
  119. first, last: int]</a></li>
  120. <li><a class="reference" href="#findBounds%2Cstring%2CRegex%2CopenArray%5Btuple%5Bint%2Cint%5D%5D%2Cint" title="findBounds(s: string; pattern: Regex;
  121. matches: var openArray[tuple[first, last: int]]; start = 0): tuple[
  122. first, last: int]">findBounds(s: string; pattern: Regex;
  123. matches: var openArray[tuple[first, last: int]]; start = 0): tuple[
  124. first, last: int]</a></li>
  125. <li><a class="reference" href="#findBounds%2Cstring%2CRegex%2CopenArray%5Bstring%5D%2Cint" title="findBounds(s: string; pattern: Regex; matches: var openArray[string]; start = 0): tuple[
  126. first, last: int]">findBounds(s: string; pattern: Regex; matches: var openArray[string]; start = 0): tuple[
  127. first, last: int]</a></li>
  128. <li><a class="reference" href="#findBounds%2Cstring%2CRegex%2Cint" title="findBounds(s: string; pattern: Regex; start = 0): tuple[first, last: int]">findBounds(s: string; pattern: Regex; start = 0): tuple[first, last: int]</a></li>
  129. </ul>
  130. <ul class="simple nested-toc-section">match
  131. <li><a class="reference" href="#match%2Ccstring%2CRegex%2CopenArray%5Bstring%5D%2Cint%2Cint" title="match(buf: cstring; pattern: Regex; matches: var openArray[string]; start = 0;
  132. bufSize: int): bool">match(buf: cstring; pattern: Regex; matches: var openArray[string]; start = 0;
  133. bufSize: int): bool</a></li>
  134. <li><a class="reference" href="#match%2Cstring%2CRegex%2CopenArray%5Bstring%5D%2Cint" title="match(s: string; pattern: Regex; matches: var openArray[string]; start = 0): bool">match(s: string; pattern: Regex; matches: var openArray[string]; start = 0): bool</a></li>
  135. <li><a class="reference" href="#match%2Cstring%2CRegex%2Cint" title="match(s: string; pattern: Regex; start = 0): bool">match(s: string; pattern: Regex; start = 0): bool</a></li>
  136. </ul>
  137. <ul class="simple nested-toc-section">matchLen
  138. <li><a class="reference" href="#matchLen%2Ccstring%2CRegex%2CopenArray%5Bstring%5D%2Cint%2Cint" title="matchLen(buf: cstring; pattern: Regex; matches: var openArray[string];
  139. start = 0; bufSize: int): int">matchLen(buf: cstring; pattern: Regex; matches: var openArray[string];
  140. start = 0; bufSize: int): int</a></li>
  141. <li><a class="reference" href="#matchLen%2Ccstring%2CRegex%2Cint%2Cint" title="matchLen(buf: cstring; pattern: Regex; start = 0; bufSize: int): int">matchLen(buf: cstring; pattern: Regex; start = 0; bufSize: int): int</a></li>
  142. <li><a class="reference" href="#matchLen%2Cstring%2CRegex%2CopenArray%5Bstring%5D%2Cint" title="matchLen(s: string; pattern: Regex; matches: var openArray[string]; start = 0): int">matchLen(s: string; pattern: Regex; matches: var openArray[string]; start = 0): int</a></li>
  143. <li><a class="reference" href="#matchLen%2Cstring%2CRegex%2Cint" title="matchLen(s: string; pattern: Regex; start = 0): int">matchLen(s: string; pattern: Regex; start = 0): int</a></li>
  144. </ul>
  145. <ul class="simple nested-toc-section">multiReplace
  146. <li><a class="reference" href="#multiReplace%2Cstring%2CopenArray%5Btuple%5BRegex%2Cstring%5D%5D" title="multiReplace(s: string; subs: openArray[tuple[pattern: Regex, repl: string]]): string">multiReplace(s: string; subs: openArray[tuple[pattern: Regex, repl: string]]): string</a></li>
  147. </ul>
  148. <ul class="simple nested-toc-section">re
  149. <li><a class="reference" href="#re%2Cstring" title="re(s: string; flags = {reStudy}): Regex">re(s: string; flags = {reStudy}): Regex</a></li>
  150. </ul>
  151. <ul class="simple nested-toc-section">replace
  152. <li><a class="reference" href="#replace%2Cstring%2CRegex%2Cstring" title="replace(s: string; sub: Regex; by = &quot;&quot;): string">replace(s: string; sub: Regex; by = &quot;&quot;): string</a></li>
  153. </ul>
  154. <ul class="simple nested-toc-section">replacef
  155. <li><a class="reference" href="#replacef%2Cstring%2CRegex%2Cstring" title="replacef(s: string; sub: Regex; by: string): string">replacef(s: string; sub: Regex; by: string): string</a></li>
  156. </ul>
  157. <ul class="simple nested-toc-section">rex
  158. <li><a class="reference" href="#rex%2Cstring" title="rex(s: string; flags = {reStudy, reExtended}): Regex">rex(s: string; flags = {reStudy, reExtended}): Regex</a></li>
  159. </ul>
  160. <ul class="simple nested-toc-section">split
  161. <li><a class="reference" href="#split%2Cstring%2CRegex%2Cint" title="split(s: string; sep: Regex; maxsplit = -1): seq[string]">split(s: string; sep: Regex; maxsplit = -1): seq[string]</a></li>
  162. </ul>
  163. <ul class="simple nested-toc-section">startsWith
  164. <li><a class="reference" href="#startsWith%2Cstring%2CRegex" title="startsWith(s: string; prefix: Regex): bool">startsWith(s: string; prefix: Regex): bool</a></li>
  165. </ul>
  166. <ul class="simple nested-toc-section">transformFile
  167. <li><a class="reference" href="#transformFile%2Cstring%2Cstring%2CopenArray%5Btuple%5BRegex%2Cstring%5D%5D" title="transformFile(infile, outfile: string;
  168. subs: openArray[tuple[pattern: Regex, repl: string]])">transformFile(infile, outfile: string;
  169. subs: openArray[tuple[pattern: Regex, repl: string]])</a></li>
  170. </ul>
  171. </ul>
  172. </details>
  173. </li>
  174. <li>
  175. <details open>
  176. <summary><a class="reference reference-toplevel" href="#15" id="65">Iterators</a></summary>
  177. <ul class="simple simple-toc-section">
  178. <ul class="simple nested-toc-section">findAll
  179. <li><a class="reference" href="#findAll.i%2Ccstring%2CRegex%2Cint%2Cint" title="findAll(buf: cstring; pattern: Regex; start = 0; bufSize: int): string">findAll(buf: cstring; pattern: Regex; start = 0; bufSize: int): string</a></li>
  180. <li><a class="reference" href="#findAll.i%2Cstring%2CRegex%2Cint" title="findAll(s: string; pattern: Regex; start = 0): string">findAll(s: string; pattern: Regex; start = 0): string</a></li>
  181. </ul>
  182. <ul class="simple nested-toc-section">split
  183. <li><a class="reference" href="#split.i%2Cstring%2CRegex%2Cint" title="split(s: string; sep: Regex; maxsplit = -1): string">split(s: string; sep: Regex; maxsplit = -1): string</a></li>
  184. </ul>
  185. </ul>
  186. </details>
  187. </li>
  188. <li>
  189. <details open>
  190. <summary><a class="reference reference-toplevel" href="#18" id="68">Templates</a></summary>
  191. <ul class="simple simple-toc-section">
  192. <ul class="simple nested-toc-section">=~
  193. <li><a class="reference" href="#%3D~.t%2Cstring%2CRegex" title="`=~`(s: string; pattern: Regex): untyped">`=~`(s: string; pattern: Regex): untyped</a></li>
  194. </ul>
  195. </ul>
  196. </details>
  197. </li>
  198. </ul>
  199. </div>
  200. <div class="nine columns" id="content">
  201. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/re.nim#L1" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  202. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/re.nim#L1" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  203. <div id="tocRoot"></div>
  204. <p class="module-desc"><p>Regular expression support for Nim.</p>
  205. <p>This module is implemented by providing a wrapper around the <a class="reference external" href="https://www.pcre.org">PCRE (Perl-Compatible Regular Expressions)</a> C library. This means that your application will depend on the PCRE library's licence when using this module, which should not be a problem though.</p>
  206. <div class="admonition admonition-info"><span class="admonition-info-text"><b>Note:</b></span>
  207. 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>
  208. <p>PCRE's licence follows:</p>
  209. <h1><a class="toc-backref" id="licence-of-the-pcre-library" href="#licence-of-the-pcre-library">Licence of the PCRE library</a></h1><p>PCRE is a library of functions to support regular expressions whose syntax and semantics are as close as possible to those of the Perl 5 language.</p>
  210. <p>Written by Philip Hazel<br/>Copyright (c) 1997-2005 University of Cambridge<br/></p><hr />
  211. <p>Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:</p>
  212. <ul class="simple"><li>Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.</li>
  213. <li>Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.</li>
  214. <li>Neither the name of the University of Cambridge nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.</li>
  215. </ul>
  216. <p>THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</p>
  217. <h1><a class="toc-backref" id="regular-expression-syntax-and-semantics" href="#regular-expression-syntax-and-semantics">Regular expression syntax and semantics</a></h1><p>As the regular expressions supported by this module are enormous, the reader is referred to <a class="reference external" href="https://perldoc.perl.org/perlre.html">https://perldoc.perl.org/perlre.html</a> for the full documentation of Perl's regular expressions.</p>
  218. <p>Because the backslash <tt class="docutils literal"><span class="pre">\</span></tt> is a meta character both in the Nim programming language and in regular expressions, it is strongly recommended that one uses the <em>raw</em> strings of Nim, so that backslashes are interpreted by the regular expression engine:</p>
  219. <p><pre class="listing"> <span class="RawData">r&quot;\S&quot;</span> <span class="Comment"># matches any character that is not whitespace</span></pre></p>
  220. <p>A regular expression is a pattern that is matched against a subject string from left to right. Most characters stand for themselves in a pattern, and match the corresponding characters in the subject. As a trivial example, the pattern:</p>
  221. <pre>The quick brown fox</pre>
  222. <p>matches a portion of a subject string that is identical to itself. The power of regular expressions comes from the ability to include alternatives and repetitions in the pattern. These are encoded in the pattern by the use of metacharacters, which do not stand for themselves but instead are interpreted in some special way.</p>
  223. <p>There are two different sets of metacharacters: those that are recognized anywhere in the pattern except within square brackets, and those that are recognized in square brackets. Outside square brackets, the metacharacters are as follows:</p>
  224. <table border="1" class="docutils"><tr><th>meta character</th><th>meaning</th></tr>
  225. <tr><td><tt class="docutils literal"><span class="pre">\</span></tt></td><td>general escape character with several uses</td></tr>
  226. <tr><td><tt class="docutils literal"><span class="pre">^</span></tt></td><td>assert start of string (or line, in multiline mode)</td></tr>
  227. <tr><td><tt class="docutils literal"><span class="pre">$</span></tt></td><td>assert end of string (or line, in multiline mode)</td></tr>
  228. <tr><td><tt class="docutils literal"><span class="pre">.</span></tt></td><td>match any character except newline (by default)</td></tr>
  229. <tr><td><tt class="docutils literal"><span class="pre">[</span></tt></td><td>start character class definition</td></tr>
  230. <tr><td><tt class="docutils literal"><span class="pre">|</span></tt></td><td>start of alternative branch</td></tr>
  231. <tr><td><tt class="docutils literal"><span class="pre">(</span></tt></td><td>start subpattern</td></tr>
  232. <tr><td><tt class="docutils literal"><span class="pre">)</span></tt></td><td>end subpattern</td></tr>
  233. <tr><td><tt class="docutils literal"><span class="pre">{</span></tt></td><td>start min/max quantifier</td></tr>
  234. <tr><td><tt class="docutils literal"><span class="pre">?</span></tt></td><td>extends the meaning of <tt class="docutils literal"><span class="pre">(</span></tt><p>also 0 or 1 quantifier (equal to <tt class="docutils literal"><span class="pre">{0,1}</span></tt>)<br/>also quantifier minimizer<br/></p></td></tr>
  235. <tr><td><tt class="docutils literal"><span class="pre">*</span></tt></td><td>0 or more quantifier (equal to <tt class="docutils literal"><span class="pre">{0,}</span></tt>)</td></tr>
  236. <tr><td><tt class="docutils literal"><span class="pre">+</span></tt></td><td>1 or more quantifier (equal to <tt class="docutils literal"><span class="pre">{1,}</span></tt>)<p>also &quot;possessive quantifier&quot;<br/></p></td></tr>
  237. </table><p>Part of a pattern that is in square brackets is called a &quot;character class&quot;. In a character class the only metacharacters are:</p>
  238. <table border="1" class="docutils"><tr><th>meta character</th><th>meaning</th></tr>
  239. <tr><td><tt class="docutils literal"><span class="pre">\</span></tt></td><td>general escape character</td></tr>
  240. <tr><td><tt class="docutils literal"><span class="pre">^</span></tt></td><td>negate the class, but only if the first character</td></tr>
  241. <tr><td><tt class="docutils literal"><span class="pre">-</span></tt></td><td>indicates character range</td></tr>
  242. <tr><td><tt class="docutils literal"><span class="pre">[</span></tt></td><td>POSIX character class (only if followed by POSIX syntax)</td></tr>
  243. <tr><td><tt class="docutils literal"><span class="pre">]</span></tt></td><td>terminates the character class</td></tr>
  244. </table><p>The following sections describe the use of each of the metacharacters.</p>
  245. <h2><a class="toc-backref" id="regular-expression-syntax-and-semantics-backslash" href="#regular-expression-syntax-and-semantics-backslash">Backslash</a></h2><p>The <span id="backslash_1">backslash</span> character has several uses. Firstly, if it is followed by a non-alphanumeric character, it takes away any special meaning that character may have. This use of backslash as an escape character applies both inside and outside character classes.</p>
  246. <p>For example, if you want to match a <tt class="docutils literal"><span class="pre">*</span></tt> character, you write <tt class="docutils literal"><span class="pre">\*</span></tt> in the pattern. This escaping action applies whether or not the following character would otherwise be interpreted as a metacharacter, so it is always safe to precede a non-alphanumeric with backslash to specify that it stands for itself. In particular, if you want to match a backslash, you write <tt class="docutils literal"><span class="pre">\\</span></tt>.</p>
  247. <h2><a class="toc-backref" id="regular-expression-syntax-and-semantics-nonminusprinting-characters" href="#regular-expression-syntax-and-semantics-nonminusprinting-characters">Non-printing characters</a></h2><p>A second use of backslash provides a way of encoding non-printing characters in patterns in a visible manner. There is no restriction on the appearance of non-printing characters, apart from the binary zero that terminates a pattern, but when a pattern is being prepared by text editing, it is usually easier to use one of the following escape sequences than the binary character it represents:</p>
  248. <table border="1" class="docutils"><tr><th>character</th><th>meaning</th></tr>
  249. <tr><td><tt class="docutils literal"><span class="pre">\a</span></tt></td><td>alarm, that is, the BEL character (hex 07)</td></tr>
  250. <tr><td><tt class="docutils literal"><span class="pre">\e</span></tt></td><td>escape (hex 1B)</td></tr>
  251. <tr><td><tt class="docutils literal"><span class="pre">\f</span></tt></td><td>formfeed (hex 0C)</td></tr>
  252. <tr><td><tt class="docutils literal"><span class="pre">\n</span></tt></td><td>newline (hex 0A)</td></tr>
  253. <tr><td><tt class="docutils literal"><span class="pre">\r</span></tt></td><td>carriage return (hex 0D)</td></tr>
  254. <tr><td><tt class="docutils literal"><span class="pre">\t</span></tt></td><td>tab (hex 09)</td></tr>
  255. <tr><td><tt class="docutils literal"><span class="pre">\ddd</span></tt></td><td>character with octal code ddd, or backreference</td></tr>
  256. <tr><td><tt class="docutils literal"><span class="pre">\xhh</span></tt></td><td>character with hex code hh</td></tr>
  257. </table><p>After <tt class="docutils literal"><span class="pre">\x</span></tt>, from zero to two hexadecimal digits are read (letters can be in upper or lower case). In UTF-8 mode, any number of hexadecimal digits may appear between <tt class="docutils literal"><span class="pre">\x{</span></tt> and <tt class="docutils literal"><span class="pre">}</span></tt>, but the value of the character code must be less than 2^31 (that is, the maximum hexadecimal value is 7FFFFFFF). If characters other than hexadecimal digits appear between <tt class="docutils literal"><span class="pre">\x{</span></tt> and <tt class="docutils literal"><span class="pre">}</span></tt>, or if there is no terminating <tt class="docutils literal"><span class="pre">}</span></tt>, this form of escape is not recognized. Instead, the initial <tt class="docutils literal"><span class="pre">\x</span></tt> will be interpreted as a basic hexadecimal escape, with no following digits, giving a character whose value is zero.</p>
  258. <p>After <tt class="docutils literal"><span class="pre">\0</span></tt> up to two further octal digits are read. In both cases, if there are fewer than two digits, just those that are present are used. Thus the sequence <tt class="docutils literal"><span class="pre">\0\x\07</span></tt> specifies two binary zeros followed by a BEL character (code value 7). Make sure you supply two digits after the initial zero if the pattern character that follows is itself an octal digit.</p>
  259. <p>The handling of a backslash followed by a digit other than 0 is complicated. Outside a character class, PCRE reads it and any following digits as a decimal number. If the number is less than 10, or if there have been at least that many previous capturing left parentheses in the expression, the entire sequence is taken as a back reference. A description of how this works is given later, following the discussion of parenthesized subpatterns.</p>
  260. <p>Inside a character class, or if the decimal number is greater than 9 and there have not been that many capturing subpatterns, PCRE re-reads up to three octal digits following the backslash, and generates a single byte from the least significant 8 bits of the value. Any subsequent digits stand for themselves. For example:</p>
  261. <table border="1" class="docutils"><tr><th>example</th><th>meaning</th></tr>
  262. <tr><td><tt class="docutils literal"><span class="pre">\040</span></tt></td><td>is another way of writing a space</td></tr>
  263. <tr><td><tt class="docutils literal"><span class="pre">\40</span></tt></td><td>is the same, provided there are fewer than 40 previous capturing subpatterns</td></tr>
  264. <tr><td><tt class="docutils literal"><span class="pre">\7</span></tt></td><td>is always a back reference</td></tr>
  265. <tr><td><tt class="docutils literal"><span class="pre">\11</span></tt></td><td>might be a back reference, or another way of writing a tab</td></tr>
  266. <tr><td><tt class="docutils literal"><span class="pre">\011</span></tt></td><td>is always a tab</td></tr>
  267. <tr><td><tt class="docutils literal"><span class="pre">\0113</span></tt></td><td>is a tab followed by the character &quot;3&quot;</td></tr>
  268. <tr><td><tt class="docutils literal"><span class="pre">\113</span></tt></td><td>might be a back reference, otherwise the character with octal code 113</td></tr>
  269. <tr><td><tt class="docutils literal"><span class="pre">\377</span></tt></td><td>might be a back reference, otherwise the byte consisting entirely of 1 bits</td></tr>
  270. <tr><td><tt class="docutils literal"><span class="pre">\81</span></tt></td><td>is either a back reference, or a binary zero followed by the two characters &quot;8&quot; and &quot;1&quot;</td></tr>
  271. </table><p>Note that octal values of 100 or greater must not be introduced by a leading zero, because no more than three octal digits are ever read.</p>
  272. <p>All the sequences that define a single byte value or a single UTF-8 character (in UTF-8 mode) can be used both inside and outside character classes. In addition, inside a character class, the sequence <tt class="docutils literal"><span class="pre">\b</span></tt> is interpreted as the backspace character (hex 08), and the sequence <tt class="docutils literal"><span class="pre">\X</span></tt> is interpreted as the character &quot;X&quot;. Outside a character class, these sequences have different meanings (see below).</p>
  273. <h2><a class="toc-backref" id="regular-expression-syntax-and-semantics-generic-character-types" href="#regular-expression-syntax-and-semantics-generic-character-types">Generic character types</a></h2><p>The third use of backslash is for specifying <span id="generic-character-types_1">generic character types</span>. The following are always recognized:</p>
  274. <table border="1" class="docutils"><tr><th>character type</th><th>meaning</th></tr>
  275. <tr><td><tt class="docutils literal"><span class="pre">\d</span></tt></td><td>any decimal digit</td></tr>
  276. <tr><td><tt class="docutils literal"><span class="pre">\D</span></tt></td><td>any character that is not a decimal digit</td></tr>
  277. <tr><td><tt class="docutils literal"><span class="pre">\s</span></tt></td><td>any whitespace character</td></tr>
  278. <tr><td><tt class="docutils literal"><span class="pre">\S</span></tt></td><td>any character that is not a whitespace character</td></tr>
  279. <tr><td><tt class="docutils literal"><span class="pre">\w</span></tt></td><td>any &quot;word&quot; character</td></tr>
  280. <tr><td><tt class="docutils literal"><span class="pre">\W</span></tt></td><td>any &quot;non-word&quot; character</td></tr>
  281. </table><p>Each pair of escape sequences partitions the complete set of characters into two disjoint sets. Any given character matches one, and only one, of each pair.</p>
  282. <p>These character type sequences can appear both inside and outside character classes. They each match one character of the appropriate type. If the current matching point is at the end of the subject string, all of them fail, since there is no character to match.</p>
  283. <p>For compatibility with Perl, <tt class="docutils literal"><span class="pre">\s</span></tt> does not match the VT character (code 11). This makes it different from the POSIX &quot;space&quot; class. The <tt class="docutils literal"><span class="pre">\s</span></tt> characters are HT (9), LF (10), FF (12), CR (13), and space (32).</p>
  284. <p>A &quot;word&quot; character is an underscore or any character less than 256 that is a letter or digit. The definition of letters and digits is controlled by PCRE's low-valued character tables, and may vary if locale-specific matching is taking place (see &quot;Locale support&quot; in the pcreapi page). For example, in the &quot;fr_FR&quot; (French) locale, some character codes greater than 128 are used for accented letters, and these are matched by <tt class="docutils literal"><span class="pre">\w</span></tt>.</p>
  285. <p>In UTF-8 mode, characters with values greater than 128 never match <tt class="docutils literal"><span class="pre">\d</span></tt>, <tt class="docutils literal"><span class="pre">\s</span></tt>, or <tt class="docutils literal"><span class="pre">\w</span></tt>, and always match <tt class="docutils literal"><span class="pre">\D</span></tt>, <tt class="docutils literal"><span class="pre">\S</span></tt>, and <tt class="docutils literal"><span class="pre">\W</span></tt>. This is true even when Unicode character property support is available.</p>
  286. <h2><a class="toc-backref" id="regular-expression-syntax-and-semantics-simple-assertions" href="#regular-expression-syntax-and-semantics-simple-assertions">Simple assertions</a></h2><p>The fourth use of backslash is for certain <span id="simple-assertions_1">simple assertions</span>. An assertion specifies a condition that has to be met at a particular point in a match, without consuming any characters from the subject string. The use of subpatterns for more complicated assertions is described below. The backslashed assertions are:</p>
  287. <table border="1" class="docutils"><tr><th>assertion</th><th>meaning</th></tr>
  288. <tr><td><tt class="docutils literal"><span class="pre">\b</span></tt></td><td>matches at a word boundary</td></tr>
  289. <tr><td><tt class="docutils literal"><span class="pre">\B</span></tt></td><td>matches when not at a word boundary</td></tr>
  290. <tr><td><tt class="docutils literal"><span class="pre">\A</span></tt></td><td>matches at start of subject</td></tr>
  291. <tr><td><tt class="docutils literal"><span class="pre">\Z</span></tt></td><td>matches at end of subject or before newline at end</td></tr>
  292. <tr><td><tt class="docutils literal"><span class="pre">\z</span></tt></td><td>matches at end of subject</td></tr>
  293. <tr><td><tt class="docutils literal"><span class="pre">\G</span></tt></td><td>matches at first matching position in subject</td></tr>
  294. </table><p>These assertions may not appear in character classes (but note that <tt class="docutils literal"><span class="pre">\b</span></tt> has a different meaning, namely the backspace character, inside a character class).</p>
  295. <p>A word boundary is a position in the subject string where the current character and the previous character do not both match <tt class="docutils literal"><span class="pre">\w</span></tt> or <tt class="docutils literal"><span class="pre">\W</span></tt> (i.e. one matches <tt class="docutils literal"><span class="pre">\w</span></tt> and the other matches <tt class="docutils literal"><span class="pre">\W</span></tt>), or the start or end of the string if the first or last character matches <tt class="docutils literal"><span class="pre">\w</span></tt>, respectively.</p>
  296. <p>The <tt class="docutils literal"><span class="pre">\A</span></tt>, <tt class="docutils literal"><span class="pre">\Z</span></tt>, and <tt class="docutils literal"><span class="pre">\z</span></tt> assertions differ from the traditional circumflex and dollar in that they only ever match at the very start and end of the subject string, whatever options are set. The difference between <tt class="docutils literal"><span class="pre">\Z</span></tt> and <tt class="docutils literal"><span class="pre">\z</span></tt> is that <tt class="docutils literal"><span class="pre">\Z</span></tt> matches before a newline that is the last character of the string as well as at the end of the string, whereas <tt class="docutils literal"><span class="pre">\z</span></tt> matches only at the end. </p>
  297. <p><strong class="examples_text">Example:</strong></p>
  298. <pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">re</span>
  299. <span class="Comment">## Unless specified otherwise, `start` parameter in each proc indicates</span>
  300. <span class="Comment">## where the scan starts, but outputs are relative to the start of the input</span>
  301. <span class="Comment">## string, not to `start`:</span>
  302. <span class="Identifier">doAssert</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="DecNumber">2</span> <span class="Comment"># lookbehind assertion</span>
  303. <span class="Identifier">doAssert</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="Operator">-</span><span class="DecNumber">1</span> <span class="Comment"># we're past `start` =&gt; not found</span>
  304. <span class="Identifier">doAssert</span> <span class="Keyword">not</span> <span class="Identifier">match</span><span class="Punctuation">(</span><span class="StringLit">&quot;xabc&quot;</span><span class="Punctuation">,</span> <span class="RawData">re&quot;^abc$&quot;</span><span class="Punctuation">,</span> <span class="Identifier">start</span> <span class="Operator">=</span> <span class="DecNumber">1</span><span class="Punctuation">)</span>
  305. <span class="Comment"># can't match start of string since we're starting at 1</span></pre></p>
  306. <div class="section" id="6">
  307. <h1><a class="toc-backref" href="#6">Imports</a></h1>
  308. <dl class="item">
  309. <a class="reference external" href="pcre.html">pcre</a>, <a class="reference external" href="strutils.html">strutils</a>, <a class="reference external" href="rtarrays.html">rtarrays</a>, <a class="reference external" href="syncio.html">syncio</a>
  310. </dl>
  311. </div>
  312. <div class="section" id="7">
  313. <h1><a class="toc-backref" href="#7">Types</a></h1>
  314. <dl class="item">
  315. <div id="Regex">
  316. <dt><pre><a href="re.html#Regex"><span class="Identifier">Regex</span></a> <span class="Other">=</span> <span class="Keyword">ref</span> <span class="Identifier">RegexDesc</span></pre></dt>
  317. <dd>
  318. a compiled regular expression
  319. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/re.nim#L62" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  320. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/re.nim#L62" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  321. </dd>
  322. </div>
  323. <div id="RegexError">
  324. <dt><pre><a href="re.html#RegexError"><span class="Identifier">RegexError</span></a> <span class="Other">=</span> <span class="Keyword">object</span> <span class="Keyword">of</span> <a href="exceptions.html#ValueError"><span class="Identifier">ValueError</span></a></pre></dt>
  325. <dd>
  326. is raised if the pattern is no valid regular expression.
  327. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/re.nim#L64" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  328. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/re.nim#L64" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  329. </dd>
  330. </div>
  331. <div id="RegexFlag">
  332. <dt><pre><a href="re.html#RegexFlag"><span class="Identifier">RegexFlag</span></a> <span class="Other">=</span> <span class="Keyword">enum</span>
  333. <span class="Identifier">reIgnoreCase</span> <span class="Other">=</span> <span class="DecNumber">0</span><span class="Other">,</span> <span class="Comment">## do caseless matching</span>
  334. <span class="Identifier">reMultiLine</span> <span class="Other">=</span> <span class="DecNumber">1</span><span class="Other">,</span> <span class="Comment">## `^` and `$` match newlines within data</span>
  335. <span class="Identifier">reDotAll</span> <span class="Other">=</span> <span class="DecNumber">2</span><span class="Other">,</span> <span class="Comment">## `.` matches anything including NL</span>
  336. <span class="Identifier">reExtended</span> <span class="Other">=</span> <span class="DecNumber">3</span><span class="Other">,</span> <span class="Comment">## ignore whitespace and `#` comments</span>
  337. <span class="Identifier">reStudy</span> <span class="Other">=</span> <span class="DecNumber">4</span> <span class="Comment">## study the expression (may be omitted if the</span>
  338. <span class="Comment">## expression will be used only once)</span></pre></dt>
  339. <dd>
  340. options for regular expressions
  341. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/re.nim#L50" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  342. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/re.nim#L50" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  343. </dd>
  344. </div>
  345. </dl>
  346. </div>
  347. <div class="section" id="10">
  348. <h1><a class="toc-backref" href="#10">Consts</a></h1>
  349. <dl class="item">
  350. <div id="MaxReBufSize">
  351. <dt><pre><a href="re.html#MaxReBufSize"><span class="Identifier">MaxReBufSize</span></a> <span class="Other">=</span> <span class="DecNumber">2147483647'i32</span></pre></dt>
  352. <dd>
  353. Maximum PCRE (API 1) buffer start/size equal to <tt class="docutils literal"><span class="pre"><span class="Identifier">high</span><span class="Punctuation">(</span><span class="Identifier">cint</span><span class="Punctuation">)</span></span></tt>, which even for 64-bit systems can be either 2<sup>31</sup>-1 or 2<sup>63</sup>-1.
  354. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/re.nim#L157" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  355. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/re.nim#L157" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  356. </dd>
  357. </div>
  358. <div id="MaxSubpatterns">
  359. <dt><pre><a href="re.html#MaxSubpatterns"><span class="Identifier">MaxSubpatterns</span></a> <span class="Other">=</span> <span class="DecNumber">20</span></pre></dt>
  360. <dd>
  361. defines the maximum number of subpatterns that can be captured. This limit still exists for <tt class="docutils literal"><span class="pre"><span class="Identifier">replacef</span></span></tt> and <tt class="docutils literal"><span class="pre"><span class="Identifier">parallelReplace</span></span></tt>.
  362. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/re.nim#L45" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  363. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/re.nim#L45" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  364. </dd>
  365. </div>
  366. </dl>
  367. </div>
  368. <div class="section" id="12">
  369. <h1><a class="toc-backref" href="#12">Procs</a></h1>
  370. <dl class="item">
  371. <div id="contains-procs-all">
  372. <div id="contains,string,Regex,openArray[string],int">
  373. <dt><pre><span class="Keyword">proc</span> <a href="#contains%2Cstring%2CRegex%2CopenArray%5Bstring%5D%2Cint"><span class="Identifier">contains</span></a><span class="Other">(</span><span class="Identifier">s</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="re.html#Regex"><span class="Identifier">Regex</span></a><span class="Other">;</span> <span class="Identifier">matches</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="system.html#openArray"><span class="Identifier">openArray</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>
  374. <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#bool"><span class="Identifier">bool</span></a> {.<span class="Identifier">inline</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  375. <dd>
  376. same as <tt class="docutils literal"><span class="pre"><span class="Identifier">find</span><span class="Punctuation">(</span><span class="Identifier">s</span><span class="Punctuation">,</span> <span class="Identifier">pattern</span><span class="Punctuation">,</span> <span class="Identifier">matches</span><span class="Punctuation">,</span> <span class="Identifier">start</span><span class="Punctuation">)</span> <span class="Operator">&gt;=</span> <span class="DecNumber">0</span></span></tt><div class="admonition admonition-info"><span class="admonition-info-text"><b>Note:</b></span>
  377. The memory for <tt class="docutils literal"><span class="pre"><span class="Identifier">matches</span></span></tt> needs to be allocated before this function is called, otherwise it will just remain empty.</div>
  378. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/re.nim#L478" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  379. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/re.nim#L478" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  380. </dd>
  381. </div>
  382. <div id="contains,string,Regex,int">
  383. <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">s</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="re.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="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a> {.<span class="Identifier">inline</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
  384. <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>
  385. <dd>
  386. same as <tt class="docutils literal"><span class="pre"><span class="Identifier">find</span><span class="Punctuation">(</span><span class="Identifier">s</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="Operator">&gt;=</span> <span class="DecNumber">0</span></span></tt>
  387. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/re.nim#L474" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  388. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/re.nim#L474" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  389. </dd>
  390. </div>
  391. </div>
  392. <div id="endsWith-procs-all">
  393. <div id="endsWith,string,Regex">
  394. <dt><pre><span class="Keyword">proc</span> <a href="#endsWith%2Cstring%2CRegex"><span class="Identifier">endsWith</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">suffix</span><span class="Other">:</span> <a href="re.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 class="Identifier">inline</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
  395. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  396. <dd>
  397. returns true if <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> ends with the pattern <tt class="docutils literal"><span class="pre"><span class="Identifier">suffix</span></span></tt>
  398. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/re.nim#L489" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  399. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/re.nim#L489" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  400. </dd>
  401. </div>
  402. </div>
  403. <div id="escapeRe-procs-all">
  404. <div id="escapeRe,string">
  405. <dt><pre><span class="Keyword">proc</span> <a href="#escapeRe%2Cstring"><span class="Identifier">escapeRe</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  406. <dd>
  407. escapes <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> so that it is matched verbatim when used as a regular expression.
  408. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/re.nim#L601" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  409. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/re.nim#L601" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  410. </dd>
  411. </div>
  412. </div>
  413. <div id="find-procs-all">
  414. <div id="find,cstring,Regex,openArray[string],int,int">
  415. <dt><pre><span class="Keyword">proc</span> <a href="#find%2Ccstring%2CRegex%2CopenArray%5Bstring%5D%2Cint%2Cint"><span class="Identifier">find</span></a><span class="Other">(</span><span class="Identifier">buf</span><span class="Other">:</span> <a href="system.html#cstring"><span class="Identifier">cstring</span></a><span class="Other">;</span> <span class="Identifier">pattern</span><span class="Other">:</span> <a href="re.html#Regex"><span class="Identifier">Regex</span></a><span class="Other">;</span> <span class="Identifier">matches</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="system.html#openArray"><span class="Identifier">openArray</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>
  416. <span class="Identifier">start</span> <span class="Other">=</span> <span class="DecNumber">0</span><span class="Other">;</span> <span class="Identifier">bufSize</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#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="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>
  417. <dd>
  418. returns the starting position of <tt class="docutils literal"><span class="pre"><span class="Identifier">pattern</span></span></tt> in <tt class="docutils literal"><span class="pre"><span class="Identifier">buf</span></span></tt> and the captured substrings in the array <tt class="docutils literal"><span class="pre"><span class="Identifier">matches</span></span></tt>. If it does not match, nothing is written into <tt class="docutils literal"><span class="pre"><span class="Identifier">matches</span></span></tt> and <tt class="docutils literal"><span class="pre"><span class="Operator">-</span><span class="DecNumber">1</span></span></tt> is returned. <tt class="docutils literal"><span class="pre"><span class="Identifier">buf</span></span></tt> has length <tt class="docutils literal"><span class="pre"><span class="Identifier">bufSize</span></span></tt> (not necessarily <tt class="docutils literal"><span class="pre"><span class="CharLit">'\0'</span></span></tt> terminated).<div class="admonition admonition-info"><span class="admonition-info-text"><b>Note:</b></span>
  419. The memory for <tt class="docutils literal"><span class="pre"><span class="Identifier">matches</span></span></tt> needs to be allocated before this function is called, otherwise it will just remain empty.</div>
  420. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/re.nim#L352" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  421. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/re.nim#L352" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  422. </dd>
  423. </div>
  424. <div id="find,cstring,Regex,int,int">
  425. <dt><pre><span class="Keyword">proc</span> <a href="#find%2Ccstring%2CRegex%2Cint%2Cint"><span class="Identifier">find</span></a><span class="Other">(</span><span class="Identifier">buf</span><span class="Other">:</span> <a href="system.html#cstring"><span class="Identifier">cstring</span></a><span class="Other">;</span> <span class="Identifier">pattern</span><span class="Other">:</span> <a href="re.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">bufSize</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#int"><span class="Identifier">int</span></a> {.
  426. <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>
  427. <dd>
  428. returns the starting position of <tt class="docutils literal"><span class="pre"><span class="Identifier">pattern</span></span></tt> in <tt class="docutils literal"><span class="pre"><span class="Identifier">buf</span></span></tt>, where <tt class="docutils literal"><span class="pre"><span class="Identifier">buf</span></span></tt> has length <tt class="docutils literal"><span class="pre"><span class="Identifier">bufSize</span></span></tt> (not necessarily <tt class="docutils literal"><span class="pre"><span class="CharLit">'\0'</span></span></tt> terminated). If it does not match, <tt class="docutils literal"><span class="pre"><span class="Operator">-</span><span class="DecNumber">1</span></span></tt> is returned.
  429. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/re.nim#L382" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  430. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/re.nim#L382" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  431. </dd>
  432. </div>
  433. <div id="find,string,Regex,openArray[string],int">
  434. <dt><pre><span class="Keyword">proc</span> <a href="#find%2Cstring%2CRegex%2CopenArray%5Bstring%5D%2Cint"><span class="Identifier">find</span></a><span class="Other">(</span><span class="Identifier">s</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="re.html#Regex"><span class="Identifier">Regex</span></a><span class="Other">;</span> <span class="Identifier">matches</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="system.html#openArray"><span class="Identifier">openArray</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">start</span> <span class="Other">=</span> <span class="DecNumber">0</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.
  435. <span class="Identifier">inline</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  436. <dd>
  437. returns the starting position of <tt class="docutils literal"><span class="pre"><span class="Identifier">pattern</span></span></tt> in <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> and the captured substrings in the array <tt class="docutils literal"><span class="pre"><span class="Identifier">matches</span></span></tt>. If it does not match, nothing is written into <tt class="docutils literal"><span class="pre"><span class="Identifier">matches</span></span></tt> and <tt class="docutils literal"><span class="pre"><span class="Operator">-</span><span class="DecNumber">1</span></span></tt> is returned.<div class="admonition admonition-info"><span class="admonition-info-text"><b>Note:</b></span>
  438. The memory for <tt class="docutils literal"><span class="pre"><span class="Identifier">matches</span></span></tt> needs to be allocated before this function is called, otherwise it will just remain empty.</div>
  439. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/re.nim#L373" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  440. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/re.nim#L373" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  441. </dd>
  442. </div>
  443. <div id="find,string,Regex,int">
  444. <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">s</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="re.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="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.<span class="Identifier">inline</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
  445. <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>
  446. <dd>
  447. returns the starting position of <tt class="docutils literal"><span class="pre"><span class="Identifier">pattern</span></span></tt> in <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>. If it does not match, <tt class="docutils literal"><span class="pre"><span class="Operator">-</span><span class="DecNumber">1</span></span></tt> is returned. We start the scan at <tt class="docutils literal"><span class="pre"><span class="Identifier">start</span></span></tt>.
  448. <p><strong class="examples_text">Example:</strong></p>
  449. <pre class="listing"><span class="Identifier">doAssert</span> <span class="Identifier">find</span><span class="Punctuation">(</span><span class="StringLit">&quot;abcdefg&quot;</span><span class="Punctuation">,</span> <span class="RawData">re&quot;cde&quot;</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">2</span>
  450. <span class="Identifier">doAssert</span> <span class="Identifier">find</span><span class="Punctuation">(</span><span class="StringLit">&quot;abcdefg&quot;</span><span class="Punctuation">,</span> <span class="RawData">re&quot;abc&quot;</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">0</span>
  451. <span class="Identifier">doAssert</span> <span class="Identifier">find</span><span class="Punctuation">(</span><span class="StringLit">&quot;abcdefg&quot;</span><span class="Punctuation">,</span> <span class="RawData">re&quot;zz&quot;</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="Operator">-</span><span class="DecNumber">1</span> <span class="Comment"># not found</span>
  452. <span class="Identifier">doAssert</span> <span class="Identifier">find</span><span class="Punctuation">(</span><span class="StringLit">&quot;abcdefg&quot;</span><span class="Punctuation">,</span> <span class="RawData">re&quot;cde&quot;</span><span class="Punctuation">,</span> <span class="Identifier">start</span> <span class="Operator">=</span> <span class="DecNumber">2</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">2</span> <span class="Comment"># still 2</span>
  453. <span class="Identifier">doAssert</span> <span class="Identifier">find</span><span class="Punctuation">(</span><span class="StringLit">&quot;abcdefg&quot;</span><span class="Punctuation">,</span> <span class="RawData">re&quot;cde&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="Operator">-</span><span class="DecNumber">1</span> <span class="Comment"># we're past the start position</span>
  454. <span class="Identifier">doAssert</span> <span class="Identifier">find</span><span class="Punctuation">(</span><span class="StringLit">&quot;xabc&quot;</span><span class="Punctuation">,</span> <span class="RawData">re&quot;(?&lt;=x|y)abc&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="DecNumber">1</span>
  455. <span class="Comment"># lookbehind assertion `(?&lt;=x|y)` can look behind `start`</span></pre>
  456. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/re.nim#L394" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  457. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/re.nim#L394" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  458. </dd>
  459. </div>
  460. </div>
  461. <div id="findAll-procs-all">
  462. <div id="findAll,string,Regex,int">
  463. <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">s</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="re.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="Other">:</span> <a href="system.html#seq"><span class="Identifier">seq</span></a><span class="Other">[</span><a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">]</span> {.<span class="Identifier">inline</span><span class="Other">,</span>
  464. <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>
  465. <dd>
  466. returns all matching <tt class="docutils literal"><span class="pre"><span class="Identifier">substrings</span></span></tt> of <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> that match <tt class="docutils literal"><span class="pre"><span class="Identifier">pattern</span></span></tt>. If it does not match, <tt class="docutils literal"><span class="pre"><span class="Operator">@</span><span class="Punctuation">[</span><span class="Punctuation">]</span></span></tt> is returned.
  467. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/re.nim#L447" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  468. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/re.nim#L447" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  469. </dd>
  470. </div>
  471. </div>
  472. <div id="findBounds-procs-all">
  473. <div id="findBounds,cstring,Regex,openArray[tuple[int,int]],int,int">
  474. <dt><pre><span class="Keyword">proc</span> <a href="#findBounds%2Ccstring%2CRegex%2CopenArray%5Btuple%5Bint%2Cint%5D%5D%2Cint%2Cint"><span class="Identifier">findBounds</span></a><span class="Other">(</span><span class="Identifier">buf</span><span class="Other">:</span> <a href="system.html#cstring"><span class="Identifier">cstring</span></a><span class="Other">;</span> <span class="Identifier">pattern</span><span class="Other">:</span> <a href="re.html#Regex"><span class="Identifier">Regex</span></a><span class="Other">;</span>
  475. <span class="Identifier">matches</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="system.html#openArray"><span class="Identifier">openArray</span></a><span class="Other">[</span><span class="Keyword">tuple</span><span class="Other">[</span><span class="Identifier">first</span><span class="Other">,</span> <span class="Identifier">last</span><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="Identifier">start</span> <span class="Other">=</span> <span class="DecNumber">0</span><span class="Other">;</span>
  476. <span class="Identifier">bufSize</span><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="Keyword">tuple</span><span class="Other">[</span><span class="Identifier">first</span><span class="Other">,</span> <span class="Identifier">last</span><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>
  477. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  478. <dd>
  479. returns the starting position and end position of <tt class="docutils literal"><span class="pre"><span class="Identifier">pattern</span></span></tt> in <tt class="docutils literal"><span class="pre"><span class="Identifier">buf</span></span></tt> (where <tt class="docutils literal"><span class="pre"><span class="Identifier">buf</span></span></tt> has length <tt class="docutils literal"><span class="pre"><span class="Identifier">bufSize</span></span></tt> and is not necessarily <tt class="docutils literal"><span class="pre"><span class="CharLit">'\0'</span></span></tt> terminated), and the captured substrings in the array <tt class="docutils literal"><span class="pre"><span class="Identifier">matches</span></span></tt>. If it does not match, nothing is written into <tt class="docutils literal"><span class="pre"><span class="Identifier">matches</span></span></tt> and <tt class="docutils literal"><span class="pre"><span class="Punctuation">(</span><span class="Operator">-</span><span class="DecNumber">1</span><span class="Punctuation">,</span><span class="DecNumber">0</span><span class="Punctuation">)</span></span></tt> is returned.<div class="admonition admonition-info"><span class="admonition-info-text"><b>Note:</b></span>
  480. The memory for <tt class="docutils literal"><span class="pre"><span class="Identifier">matches</span></span></tt> needs to be allocated before this function is called, otherwise it will just remain empty.</div>
  481. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/re.nim#L201" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  482. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/re.nim#L201" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  483. </dd>
  484. </div>
  485. <div id="findBounds,cstring,Regex,openArray[string],int,int">
  486. <dt><pre><span class="Keyword">proc</span> <a href="#findBounds%2Ccstring%2CRegex%2CopenArray%5Bstring%5D%2Cint%2Cint"><span class="Identifier">findBounds</span></a><span class="Other">(</span><span class="Identifier">buf</span><span class="Other">:</span> <a href="system.html#cstring"><span class="Identifier">cstring</span></a><span class="Other">;</span> <span class="Identifier">pattern</span><span class="Other">:</span> <a href="re.html#Regex"><span class="Identifier">Regex</span></a><span class="Other">;</span> <span class="Identifier">matches</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="system.html#openArray"><span class="Identifier">openArray</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>
  487. <span class="Identifier">start</span> <span class="Other">=</span> <span class="DecNumber">0</span><span class="Other">;</span> <span class="Identifier">bufSize</span><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="Keyword">tuple</span><span class="Other">[</span><span class="Identifier">first</span><span class="Other">,</span> <span class="Identifier">last</span><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>
  488. <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>
  489. <dd>
  490. <p>returns the starting position and end position of <tt class="docutils literal"><span class="pre"><span class="Identifier">pattern</span></span></tt> in <tt class="docutils literal"><span class="pre"><span class="Identifier">buf</span></span></tt> (where <tt class="docutils literal"><span class="pre"><span class="Identifier">buf</span></span></tt> has length <tt class="docutils literal"><span class="pre"><span class="Identifier">bufSize</span></span></tt> and is not necessarily <tt class="docutils literal"><span class="pre"><span class="CharLit">'\0'</span></span></tt> terminated), and the captured substrings in the array <tt class="docutils literal"><span class="pre"><span class="Identifier">matches</span></span></tt>. If it does not match, nothing is written into <tt class="docutils literal"><span class="pre"><span class="Identifier">matches</span></span></tt> and <tt class="docutils literal"><span class="pre"><span class="Punctuation">(</span><span class="Operator">-</span><span class="DecNumber">1</span><span class="Punctuation">,</span><span class="DecNumber">0</span><span class="Punctuation">)</span></span></tt> is returned.</p>
  491. <p>Note: The memory for <tt class="docutils literal"><span class="pre"><span class="Identifier">matches</span></span></tt> needs to be allocated before this function is called, otherwise it will just remain empty.</p>
  492. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/re.nim#L161" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  493. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/re.nim#L161" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  494. </dd>
  495. </div>
  496. <div id="findBounds,cstring,Regex,int,int">
  497. <dt><pre><span class="Keyword">proc</span> <a href="#findBounds%2Ccstring%2CRegex%2Cint%2Cint"><span class="Identifier">findBounds</span></a><span class="Other">(</span><span class="Identifier">buf</span><span class="Other">:</span> <a href="system.html#cstring"><span class="Identifier">cstring</span></a><span class="Other">;</span> <span class="Identifier">pattern</span><span class="Other">:</span> <a href="re.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">bufSize</span><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="Keyword">tuple</span><span class="Other">[</span>
  498. <span class="Identifier">first</span><span class="Other">,</span> <span class="Identifier">last</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">]</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  499. <dd>
  500. returns the <tt class="docutils literal"><span class="pre"><span class="Identifier">first</span></span></tt> and <tt class="docutils literal"><span class="pre"><span class="Identifier">last</span></span></tt> position of <tt class="docutils literal"><span class="pre"><span class="Identifier">pattern</span></span></tt> in <tt class="docutils literal"><span class="pre"><span class="Identifier">buf</span></span></tt>, where <tt class="docutils literal"><span class="pre"><span class="Identifier">buf</span></span></tt> has length <tt class="docutils literal"><span class="pre"><span class="Identifier">bufSize</span></span></tt> (not necessarily <tt class="docutils literal"><span class="pre"><span class="CharLit">'\0'</span></span></tt> terminated). If it does not match, <tt class="docutils literal"><span class="pre"><span class="Punctuation">(</span><span class="Operator">-</span><span class="DecNumber">1</span><span class="Punctuation">,</span><span class="DecNumber">0</span><span class="Punctuation">)</span></span></tt> is returned.
  501. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/re.nim#L254" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  502. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/re.nim#L254" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  503. </dd>
  504. </div>
  505. <div id="findBounds,string,Regex,openArray[tuple[int,int]],int">
  506. <dt><pre><span class="Keyword">proc</span> <a href="#findBounds%2Cstring%2CRegex%2CopenArray%5Btuple%5Bint%2Cint%5D%5D%2Cint"><span class="Identifier">findBounds</span></a><span class="Other">(</span><span class="Identifier">s</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="re.html#Regex"><span class="Identifier">Regex</span></a><span class="Other">;</span>
  507. <span class="Identifier">matches</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="system.html#openArray"><span class="Identifier">openArray</span></a><span class="Other">[</span><span class="Keyword">tuple</span><span class="Other">[</span><span class="Identifier">first</span><span class="Other">,</span> <span class="Identifier">last</span><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="Identifier">start</span> <span class="Other">=</span> <span class="DecNumber">0</span><span class="Other">)</span><span class="Other">:</span> <span class="Keyword">tuple</span><span class="Other">[</span>
  508. <span class="Identifier">first</span><span class="Other">,</span> <span class="Identifier">last</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">]</span> {.<span class="Identifier">inline</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  509. <dd>
  510. returns the starting position and end position of <tt class="docutils literal"><span class="pre"><span class="Identifier">pattern</span></span></tt> in <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> and the captured substrings in the array <tt class="docutils literal"><span class="pre"><span class="Identifier">matches</span></span></tt>. If it does not match, nothing is written into <tt class="docutils literal"><span class="pre"><span class="Identifier">matches</span></span></tt> and <tt class="docutils literal"><span class="pre"><span class="Punctuation">(</span><span class="Operator">-</span><span class="DecNumber">1</span><span class="Punctuation">,</span><span class="DecNumber">0</span><span class="Punctuation">)</span></span></tt> is returned.<div class="admonition admonition-info"><span class="admonition-info-text"><b>Note:</b></span>
  511. The memory for <tt class="docutils literal"><span class="pre"><span class="Identifier">matches</span></span></tt> needs to be allocated before this function is called, otherwise it will just remain empty.</div>
  512. <p><strong class="examples_text">Example:</strong></p>
  513. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">matches</span> <span class="Operator">=</span> <span class="Identifier">newSeq</span><span class="Punctuation">[</span><span class="Keyword">tuple</span><span class="Punctuation">[</span><span class="Identifier">first</span><span class="Punctuation">,</span> <span class="Identifier">last</span><span class="Punctuation">:</span> <span class="Identifier">int</span><span class="Punctuation">]</span><span class="Punctuation">]</span><span class="Punctuation">(</span><span class="DecNumber">1</span><span class="Punctuation">)</span>
  514. <span class="Keyword">let</span> <span class="Punctuation">(</span><span class="Identifier">first</span><span class="Punctuation">,</span> <span class="Identifier">last</span><span class="Punctuation">)</span> <span class="Operator">=</span> <span class="Identifier">findBounds</span><span class="Punctuation">(</span><span class="StringLit">&quot;Hello World&quot;</span><span class="Punctuation">,</span> <span class="RawData">re&quot;(\w+)&quot;</span><span class="Punctuation">,</span> <span class="Identifier">matches</span><span class="Punctuation">)</span>
  515. <span class="Identifier">doAssert</span> <span class="Identifier">first</span> <span class="Operator">==</span> <span class="DecNumber">0</span>
  516. <span class="Identifier">doAssert</span> <span class="Identifier">last</span> <span class="Operator">==</span> <span class="DecNumber">4</span>
  517. <span class="Identifier">doAssert</span> <span class="Identifier">matches</span><span class="Punctuation">[</span><span class="DecNumber">0</span><span class="Punctuation">]</span> <span class="Operator">==</span> <span class="Punctuation">(</span><span class="DecNumber">0</span><span class="Punctuation">,</span> <span class="DecNumber">4</span><span class="Punctuation">)</span></pre>
  518. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/re.nim#L224" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  519. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/re.nim#L224" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  520. </dd>
  521. </div>
  522. <div id="findBounds,string,Regex,openArray[string],int">
  523. <dt><pre><span class="Keyword">proc</span> <a href="#findBounds%2Cstring%2CRegex%2CopenArray%5Bstring%5D%2Cint"><span class="Identifier">findBounds</span></a><span class="Other">(</span><span class="Identifier">s</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="re.html#Regex"><span class="Identifier">Regex</span></a><span class="Other">;</span> <span class="Identifier">matches</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="system.html#openArray"><span class="Identifier">openArray</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>
  524. <span class="Identifier">start</span> <span class="Other">=</span> <span class="DecNumber">0</span><span class="Other">)</span><span class="Other">:</span> <span class="Keyword">tuple</span><span class="Other">[</span><span class="Identifier">first</span><span class="Other">,</span> <span class="Identifier">last</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">]</span> {.<span class="Identifier">inline</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
  525. <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>
  526. <dd>
  527. returns the starting position and end position of <tt class="docutils literal"><span class="pre"><span class="Identifier">pattern</span></span></tt> in <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> and the captured substrings in the array <tt class="docutils literal"><span class="pre"><span class="Identifier">matches</span></span></tt>. If it does not match, nothing is written into <tt class="docutils literal"><span class="pre"><span class="Identifier">matches</span></span></tt> and <tt class="docutils literal"><span class="pre"><span class="Punctuation">(</span><span class="Operator">-</span><span class="DecNumber">1</span><span class="Punctuation">,</span><span class="DecNumber">0</span><span class="Punctuation">)</span></span></tt> is returned.<div class="admonition admonition-info"><span class="admonition-info-text"><b>Note:</b></span>
  528. The memory for <tt class="docutils literal"><span class="pre"><span class="Identifier">matches</span></span></tt> needs to be allocated before this function is called, otherwise it will just remain empty.</div>
  529. <p><strong class="examples_text">Example:</strong></p>
  530. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">matches</span> <span class="Operator">=</span> <span class="Identifier">newSeq</span><span class="Punctuation">[</span><span class="Identifier">string</span><span class="Punctuation">]</span><span class="Punctuation">(</span><span class="DecNumber">1</span><span class="Punctuation">)</span>
  531. <span class="Keyword">let</span> <span class="Punctuation">(</span><span class="Identifier">first</span><span class="Punctuation">,</span> <span class="Identifier">last</span><span class="Punctuation">)</span> <span class="Operator">=</span> <span class="Identifier">findBounds</span><span class="Punctuation">(</span><span class="StringLit">&quot;Hello World&quot;</span><span class="Punctuation">,</span> <span class="RawData">re&quot;(W\w+)&quot;</span><span class="Punctuation">,</span> <span class="Identifier">matches</span><span class="Punctuation">)</span>
  532. <span class="Identifier">doAssert</span> <span class="Identifier">first</span> <span class="Operator">==</span> <span class="DecNumber">6</span>
  533. <span class="Identifier">doAssert</span> <span class="Identifier">last</span> <span class="Operator">==</span> <span class="DecNumber">10</span>
  534. <span class="Identifier">doAssert</span> <span class="Identifier">matches</span><span class="Punctuation">[</span><span class="DecNumber">0</span><span class="Punctuation">]</span> <span class="Operator">==</span> <span class="StringLit">&quot;World&quot;</span></pre>
  535. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/re.nim#L184" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  536. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/re.nim#L184" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  537. </dd>
  538. </div>
  539. <div id="findBounds,string,Regex,int">
  540. <dt><pre><span class="Keyword">proc</span> <a href="#findBounds%2Cstring%2CRegex%2Cint"><span class="Identifier">findBounds</span></a><span class="Other">(</span><span class="Identifier">s</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="re.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="Other">:</span> <span class="Keyword">tuple</span><span class="Other">[</span><span class="Identifier">first</span><span class="Other">,</span> <span class="Identifier">last</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">]</span> {.
  541. <span class="Identifier">inline</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  542. <dd>
  543. <p>returns the <tt class="docutils literal"><span class="pre"><span class="Identifier">first</span></span></tt> and <tt class="docutils literal"><span class="pre"><span class="Identifier">last</span></span></tt> position of <tt class="docutils literal"><span class="pre"><span class="Identifier">pattern</span></span></tt> in <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>. If it does not match, <tt class="docutils literal"><span class="pre"><span class="Punctuation">(</span><span class="Operator">-</span><span class="DecNumber">1</span><span class="Punctuation">,</span><span class="DecNumber">0</span><span class="Punctuation">)</span></span></tt> is returned.</p>
  544. <p>Note: there is a speed improvement if the matches do not need to be captured.</p>
  545. <p><strong class="examples_text">Example:</strong></p>
  546. <pre class="listing"><span class="Identifier">assert</span> <span class="Identifier">findBounds</span><span class="Punctuation">(</span><span class="StringLit">&quot;01234abc89&quot;</span><span class="Punctuation">,</span> <span class="RawData">re&quot;abc&quot;</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="Punctuation">(</span><span class="DecNumber">5</span><span class="Punctuation">,</span><span class="DecNumber">7</span><span class="Punctuation">)</span></pre>
  547. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/re.nim#L267" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  548. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/re.nim#L267" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  549. </dd>
  550. </div>
  551. </div>
  552. <div id="match-procs-all">
  553. <div id="match,cstring,Regex,openArray[string],int,int">
  554. <dt><pre><span class="Keyword">proc</span> <a href="#match%2Ccstring%2CRegex%2CopenArray%5Bstring%5D%2Cint%2Cint"><span class="Identifier">match</span></a><span class="Other">(</span><span class="Identifier">buf</span><span class="Other">:</span> <a href="system.html#cstring"><span class="Identifier">cstring</span></a><span class="Other">;</span> <span class="Identifier">pattern</span><span class="Other">:</span> <a href="re.html#Regex"><span class="Identifier">Regex</span></a><span class="Other">;</span> <span class="Identifier">matches</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="system.html#openArray"><span class="Identifier">openArray</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>
  555. <span class="Identifier">start</span> <span class="Other">=</span> <span class="DecNumber">0</span><span class="Other">;</span> <span class="Identifier">bufSize</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a> {.<span class="Identifier">inline</span><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>
  556. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  557. <dd>
  558. returns <tt class="docutils literal"><span class="pre"><span class="Identifier">true</span></span></tt> if <tt class="docutils literal"><span class="pre"><span class="Identifier">buf</span><span class="Punctuation">[</span><span class="Identifier">start</span><span class="Operator">..&lt;</span><span class="Identifier">bufSize</span><span class="Punctuation">]</span></span></tt> matches the <tt class="docutils literal"><span class="pre"><span class="Identifier">pattern</span></span></tt> and the captured substrings in the array <tt class="docutils literal"><span class="pre"><span class="Identifier">matches</span></span></tt>. If it does not match, nothing is written into <tt class="docutils literal"><span class="pre"><span class="Identifier">matches</span></span></tt> and <tt class="docutils literal"><span class="pre"><span class="Identifier">false</span></span></tt> is returned. <tt class="docutils literal"><span class="pre"><span class="Identifier">buf</span></span></tt> has length <tt class="docutils literal"><span class="pre"><span class="Identifier">bufSize</span></span></tt> (not necessarily <tt class="docutils literal"><span class="pre"><span class="CharLit">'\0'</span></span></tt> terminated).<div class="admonition admonition-info"><span class="admonition-info-text"><b>Note:</b></span>
  559. The memory for <tt class="docutils literal"><span class="pre"><span class="Identifier">matches</span></span></tt> needs to be allocated before this function is called, otherwise it will just remain empty.</div>
  560. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/re.nim#L341" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  561. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/re.nim#L341" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  562. </dd>
  563. </div>
  564. <div id="match,string,Regex,openArray[string],int">
  565. <dt><pre><span class="Keyword">proc</span> <a href="#match%2Cstring%2CRegex%2CopenArray%5Bstring%5D%2Cint"><span class="Identifier">match</span></a><span class="Other">(</span><span class="Identifier">s</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="re.html#Regex"><span class="Identifier">Regex</span></a><span class="Other">;</span> <span class="Identifier">matches</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="system.html#openArray"><span class="Identifier">openArray</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">start</span> <span class="Other">=</span> <span class="DecNumber">0</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a> {.
  566. <span class="Identifier">inline</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  567. <dd>
  568. returns <tt class="docutils literal"><span class="pre"><span class="Identifier">true</span></span></tt> if <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span><span class="Punctuation">[</span><span class="Identifier">start</span><span class="Operator">..</span><span class="Punctuation">]</span></span></tt> matches the <tt class="docutils literal"><span class="pre"><span class="Identifier">pattern</span></span></tt> and the captured substrings in the array <tt class="docutils literal"><span class="pre"><span class="Identifier">matches</span></span></tt>. If it does not match, nothing is written into <tt class="docutils literal"><span class="pre"><span class="Identifier">matches</span></span></tt> and <tt class="docutils literal"><span class="pre"><span class="Identifier">false</span></span></tt> is returned.<div class="admonition admonition-info"><span class="admonition-info-text"><b>Note:</b></span>
  569. The memory for <tt class="docutils literal"><span class="pre"><span class="Identifier">matches</span></span></tt> needs to be allocated before this function is called, otherwise it will just remain empty.</div>
  570. <p><strong class="examples_text">Example:</strong></p>
  571. <pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">sequtils</span>
  572. <span class="Keyword">var</span> <span class="Identifier">matches</span><span class="Punctuation">:</span> <span class="Identifier">array</span><span class="Punctuation">[</span><span class="DecNumber">2</span><span class="Punctuation">,</span> <span class="Identifier">string</span><span class="Punctuation">]</span>
  573. <span class="Keyword">if</span> <span class="Identifier">match</span><span class="Punctuation">(</span><span class="StringLit">&quot;abcdefg&quot;</span><span class="Punctuation">,</span> <span class="RawData">re&quot;c(d)ef(g)&quot;</span><span class="Punctuation">,</span> <span class="Identifier">matches</span><span class="Punctuation">,</span> <span class="DecNumber">2</span><span class="Punctuation">)</span><span class="Punctuation">:</span>
  574. <span class="Identifier">doAssert</span> <span class="Identifier">toSeq</span><span class="Punctuation">(</span><span class="Identifier">matches</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="Operator">@</span><span class="Punctuation">[</span><span class="StringLit">&quot;d&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;g&quot;</span><span class="Punctuation">]</span></pre>
  575. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/re.nim#L326" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  576. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/re.nim#L326" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  577. </dd>
  578. </div>
  579. <div id="match,string,Regex,int">
  580. <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">s</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="re.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="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a> {.<span class="Identifier">inline</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
  581. <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>
  582. <dd>
  583. returns <tt class="docutils literal"><span class="pre"><span class="Identifier">true</span></span></tt> if <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span><span class="Punctuation">[</span><span class="Identifier">start</span><span class="Operator">..</span><span class="Punctuation">]</span></span></tt> matches the <tt class="docutils literal"><span class="pre"><span class="Identifier">pattern</span></span></tt>.
  584. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/re.nim#L322" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  585. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/re.nim#L322" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  586. </dd>
  587. </div>
  588. </div>
  589. <div id="matchLen-procs-all">
  590. <div id="matchLen,cstring,Regex,openArray[string],int,int">
  591. <dt><pre><span class="Keyword">proc</span> <a href="#matchLen%2Ccstring%2CRegex%2CopenArray%5Bstring%5D%2Cint%2Cint"><span class="Identifier">matchLen</span></a><span class="Other">(</span><span class="Identifier">buf</span><span class="Other">:</span> <a href="system.html#cstring"><span class="Identifier">cstring</span></a><span class="Other">;</span> <span class="Identifier">pattern</span><span class="Other">:</span> <a href="re.html#Regex"><span class="Identifier">Regex</span></a><span class="Other">;</span> <span class="Identifier">matches</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="system.html#openArray"><span class="Identifier">openArray</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>
  592. <span class="Identifier">start</span> <span class="Other">=</span> <span class="DecNumber">0</span><span class="Other">;</span> <span class="Identifier">bufSize</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#int"><span class="Identifier">int</span></a> {.<span class="Identifier">inline</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
  593. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  594. <dd>
  595. the same as <tt class="docutils literal"><span class="pre"><span class="Identifier">match</span></span></tt>, but it returns the length of the match, if there is no match, <tt class="docutils literal"><span class="pre"><span class="Operator">-</span><span class="DecNumber">1</span></span></tt> is returned. Note that a match length of zero can happen.<div class="admonition admonition-info"><span class="admonition-info-text"><b>Note:</b></span>
  596. The memory for <tt class="docutils literal"><span class="pre"><span class="Identifier">matches</span></span></tt> needs to be allocated before this function is called, otherwise it will just remain empty.</div>
  597. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/re.nim#L296" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  598. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/re.nim#L296" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  599. </dd>
  600. </div>
  601. <div id="matchLen,cstring,Regex,int,int">
  602. <dt><pre><span class="Keyword">proc</span> <a href="#matchLen%2Ccstring%2CRegex%2Cint%2Cint"><span class="Identifier">matchLen</span></a><span class="Other">(</span><span class="Identifier">buf</span><span class="Other">:</span> <a href="system.html#cstring"><span class="Identifier">cstring</span></a><span class="Other">;</span> <span class="Identifier">pattern</span><span class="Other">:</span> <a href="re.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">bufSize</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#int"><span class="Identifier">int</span></a> {.
  603. <span class="Identifier">inline</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  604. <dd>
  605. the same as <tt class="docutils literal"><span class="pre"><span class="Identifier">match</span></span></tt>, but it returns the length of the match, if there is no match, <tt class="docutils literal"><span class="pre"><span class="Operator">-</span><span class="DecNumber">1</span></span></tt> is returned. Note that a match length of zero can happen.
  606. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/re.nim#L316" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  607. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/re.nim#L316" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  608. </dd>
  609. </div>
  610. <div id="matchLen,string,Regex,openArray[string],int">
  611. <dt><pre><span class="Keyword">proc</span> <a href="#matchLen%2Cstring%2CRegex%2CopenArray%5Bstring%5D%2Cint"><span class="Identifier">matchLen</span></a><span class="Other">(</span><span class="Identifier">s</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="re.html#Regex"><span class="Identifier">Regex</span></a><span class="Other">;</span> <span class="Identifier">matches</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="system.html#openArray"><span class="Identifier">openArray</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>
  612. <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#int"><span class="Identifier">int</span></a> {.<span class="Identifier">inline</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  613. <dd>
  614. the same as <tt class="docutils literal"><span class="pre"><span class="Identifier">match</span></span></tt>, but it returns the length of the match, if there is no match, <tt class="docutils literal"><span class="pre"><span class="Operator">-</span><span class="DecNumber">1</span></span></tt> is returned. Note that a match length of zero can happen.<div class="admonition admonition-info"><span class="admonition-info-text"><b>Note:</b></span>
  615. The memory for <tt class="docutils literal"><span class="pre"><span class="Identifier">matches</span></span></tt> needs to be allocated before this function is called, otherwise it will just remain empty.</div>
  616. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/re.nim#L287" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  617. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/re.nim#L287" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  618. </dd>
  619. </div>
  620. <div id="matchLen,string,Regex,int">
  621. <dt><pre><span class="Keyword">proc</span> <a href="#matchLen%2Cstring%2CRegex%2Cint"><span class="Identifier">matchLen</span></a><span class="Other">(</span><span class="Identifier">s</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="re.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="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.<span class="Identifier">inline</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
  622. <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>
  623. <dd>
  624. the same as <tt class="docutils literal"><span class="pre"><span class="Identifier">match</span></span></tt>, but it returns the length of the match, if there is no match, <tt class="docutils literal"><span class="pre"><span class="Operator">-</span><span class="DecNumber">1</span></span></tt> is returned. Note that a match length of zero can happen.
  625. <p><strong class="examples_text">Example:</strong></p>
  626. <pre class="listing"><span class="Identifier">doAssert</span> <span class="Identifier">matchLen</span><span class="Punctuation">(</span><span class="StringLit">&quot;abcdefg&quot;</span><span class="Punctuation">,</span> <span class="RawData">re&quot;cde&quot;</span><span class="Punctuation">,</span> <span class="DecNumber">2</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">3</span>
  627. <span class="Identifier">doAssert</span> <span class="Identifier">matchLen</span><span class="Punctuation">(</span><span class="StringLit">&quot;abcdefg&quot;</span><span class="Punctuation">,</span> <span class="RawData">re&quot;abcde&quot;</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">5</span>
  628. <span class="Identifier">doAssert</span> <span class="Identifier">matchLen</span><span class="Punctuation">(</span><span class="StringLit">&quot;abcdefg&quot;</span><span class="Punctuation">,</span> <span class="RawData">re&quot;cde&quot;</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="Operator">-</span><span class="DecNumber">1</span></pre>
  629. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/re.nim#L305" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  630. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/re.nim#L305" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  631. </dd>
  632. </div>
  633. </div>
  634. <div id="multiReplace-procs-all">
  635. <div id="multiReplace,string,openArray[tuple[Regex,string]]">
  636. <dt><pre><span class="Keyword">proc</span> <a href="#multiReplace%2Cstring%2CopenArray%5Btuple%5BRegex%2Cstring%5D%5D"><span class="Identifier">multiReplace</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span>
  637. <span class="Identifier">subs</span><span class="Other">:</span> <a href="system.html#openArray"><span class="Identifier">openArray</span></a><span class="Other">[</span><span class="Keyword">tuple</span><span class="Other">[</span><span class="Identifier">pattern</span><span class="Other">:</span> <a href="re.html#Regex"><span class="Identifier">Regex</span></a><span class="Other">,</span> <span class="Identifier">repl</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><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> {.
  638. <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>
  639. <dd>
  640. Returns a modified copy of <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> with the substitutions in <tt class="docutils literal"><span class="pre"><span class="Identifier">subs</span></span></tt> applied in parallel.
  641. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/re.nim#L533" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  642. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/re.nim#L533" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  643. </dd>
  644. </div>
  645. </div>
  646. <div id="re-procs-all">
  647. <div id="re,string">
  648. <dt><pre><span class="Keyword">proc</span> <a href="#re%2Cstring"><span class="Identifier">re</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">flags</span> <span class="Other">=</span> <span class="Other">{</span><span class="Identifier">reStudy</span><span class="Other">}</span><span class="Other">)</span><span class="Other">:</span> <a href="re.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">RegexError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
  649. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  650. <dd>
  651. <p>Constructor of regular expressions.</p>
  652. <p>Note that Nim's extended raw string literals support the syntax <tt class="docutils literal"><span class="pre"><span class="RawData">re&quot;[abc]&quot;</span></span></tt> as a short form for <tt class="docutils literal"><span class="pre"><span class="Identifier">re</span><span class="Punctuation">(</span><span class="RawData">r&quot;[abc]&quot;</span><span class="Punctuation">)</span></span></tt>. Also note that since this compiles the regular expression, which is expensive, you should avoid putting it directly in the arguments of the functions like the examples show below if you plan to use it a lot of times, as this will hurt performance immensely. (e.g. outside a loop, ...)</p>
  653. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/re.nim#L101" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  654. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/re.nim#L101" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  655. </dd>
  656. </div>
  657. </div>
  658. <div id="replace-procs-all">
  659. <div id="replace,string,Regex,string">
  660. <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">s</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">sub</span><span class="Other">:</span> <a href="re.html#Regex"><span class="Identifier">Regex</span></a><span class="Other">;</span> <span class="Identifier">by</span> <span class="Other">=</span> <span class="StringLit">&quot;&quot;</span><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>
  661. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  662. <dd>
  663. Replaces <tt class="docutils literal"><span class="pre"><span class="Identifier">sub</span></span></tt> in <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> by the string <tt class="docutils literal"><span class="pre"><span class="Identifier">by</span></span></tt>. Captures cannot be accessed in <tt class="docutils literal"><span class="pre"><span class="Identifier">by</span></span></tt>.
  664. <p><strong class="examples_text">Example:</strong></p>
  665. <pre class="listing"><span class="Identifier">doAssert</span> <span class="StringLit">&quot;var1=key; var2=key2&quot;</span><span class="Operator">.</span><span class="Identifier">replace</span><span class="Punctuation">(</span><span class="RawData">re&quot;(\w+)=(\w+)&quot;</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;; &quot;</span>
  666. <span class="Identifier">doAssert</span> <span class="StringLit">&quot;var1=key; var2=key2&quot;</span><span class="Operator">.</span><span class="Identifier">replace</span><span class="Punctuation">(</span><span class="RawData">re&quot;(\w+)=(\w+)&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;?&quot;</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;?; ?&quot;</span></pre>
  667. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/re.nim#L494" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  668. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/re.nim#L494" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  669. </dd>
  670. </div>
  671. </div>
  672. <div id="replacef-procs-all">
  673. <div id="replacef,string,Regex,string">
  674. <dt><pre><span class="Keyword">proc</span> <a href="#replacef%2Cstring%2CRegex%2Cstring"><span class="Identifier">replacef</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">sub</span><span class="Other">:</span> <a href="re.html#Regex"><span class="Identifier">Regex</span></a><span class="Other">;</span> <span class="Identifier">by</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">ValueError</span><span class="Other">]</span><span class="Other">,</span>
  675. <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>
  676. <dd>
  677. Replaces <tt class="docutils literal"><span class="pre"><span class="Identifier">sub</span></span></tt> in <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> by the string <tt class="docutils literal"><span class="pre"><span class="Identifier">by</span></span></tt>. Captures can be accessed in <tt class="docutils literal"><span class="pre"><span class="Identifier">by</span></span></tt> with the notation <tt class="docutils literal"><span class="pre"><span class="Operator">$</span><span class="Identifier">i</span></span></tt> and <tt class="docutils literal"><span class="pre"><span class="Operator">$</span><span class="Comment">#</span></span></tt> (see strutils.`%`).
  678. <p><strong class="examples_text">Example:</strong></p>
  679. <pre class="listing"><span class="Identifier">doAssert</span> <span class="StringLit">&quot;var1=key; var2=key2&quot;</span><span class="Operator">.</span><span class="Identifier">replacef</span><span class="Punctuation">(</span><span class="RawData">re&quot;(\w+)=(\w+)&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;$1&lt;-$2$2&quot;</span><span class="Punctuation">)</span> <span class="Operator">==</span>
  680. <span class="StringLit">&quot;var1&lt;-keykey; var2&lt;-key2key2&quot;</span></pre>
  681. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/re.nim#L515" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  682. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/re.nim#L515" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  683. </dd>
  684. </div>
  685. </div>
  686. <div id="rex-procs-all">
  687. <div id="rex,string">
  688. <dt><pre><span class="Keyword">proc</span> <a href="#rex%2Cstring"><span class="Identifier">rex</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">flags</span> <span class="Other">=</span> <span class="Other">{</span><span class="Identifier">reStudy</span><span class="Other">,</span> <span class="Identifier">reExtended</span><span class="Other">}</span><span class="Other">)</span><span class="Other">:</span> <a href="re.html#Regex"><span class="Identifier">Regex</span></a> {.
  689. <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">RegexError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  690. <dd>
  691. <p>Constructor for extended regular expressions.</p>
  692. <p>The extended means that comments starting with <tt class="docutils literal"><span class="pre"><span class="Comment">#</span></span></tt> and whitespace are ignored.</p>
  693. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/re.nim#L126" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  694. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/re.nim#L126" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  695. </dd>
  696. </div>
  697. </div>
  698. <div id="split-procs-all">
  699. <div id="split,string,Regex,int">
  700. <dt><pre><span class="Keyword">proc</span> <a href="#split%2Cstring%2CRegex%2Cint"><span class="Identifier">split</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">sep</span><span class="Other">:</span> <a href="re.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="Other">:</span> <a href="system.html#seq"><span class="Identifier">seq</span></a><span class="Other">[</span><a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">]</span> {.<span class="Identifier">inline</span><span class="Other">,</span>
  701. <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>
  702. <dd>
  703. <p>Splits the string <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> into a seq of substrings.</p>
  704. <p>The portion matched by <tt class="docutils literal"><span class="pre"><span class="Identifier">sep</span></span></tt> is not returned.</p>
  705. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/re.nim#L594" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  706. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/re.nim#L594" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  707. </dd>
  708. </div>
  709. </div>
  710. <div id="startsWith-procs-all">
  711. <div id="startsWith,string,Regex">
  712. <dt><pre><span class="Keyword">proc</span> <a href="#startsWith%2Cstring%2CRegex"><span class="Identifier">startsWith</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">prefix</span><span class="Other">:</span> <a href="re.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 class="Identifier">inline</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
  713. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  714. <dd>
  715. returns true if <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> starts with the pattern <tt class="docutils literal"><span class="pre"><span class="Identifier">prefix</span></span></tt>
  716. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/re.nim#L485" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  717. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/re.nim#L485" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  718. </dd>
  719. </div>
  720. </div>
  721. <div id="transformFile-procs-all">
  722. <div id="transformFile,string,string,openArray[tuple[Regex,string]]">
  723. <dt><pre><span class="Keyword">proc</span> <a href="#transformFile%2Cstring%2Cstring%2CopenArray%5Btuple%5BRegex%2Cstring%5D%5D"><span class="Identifier">transformFile</span></a><span class="Other">(</span><span class="Identifier">infile</span><span class="Other">,</span> <span class="Identifier">outfile</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span>
  724. <span class="Identifier">subs</span><span class="Other">:</span> <a href="system.html#openArray"><span class="Identifier">openArray</span></a><span class="Other">[</span><span class="Keyword">tuple</span><span class="Other">[</span><span class="Identifier">pattern</span><span class="Other">:</span> <a href="re.html#Regex"><span class="Identifier">Regex</span></a><span class="Other">,</span> <span class="Identifier">repl</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> {.
  725. <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">IOError</span><span class="Other">,</span> <span class="Identifier">ValueError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">ReadIOEffect</span><span class="Other">,</span> <span class="Identifier">WriteIOEffect</span><span class="Other">]</span><span class="Other">,</span>
  726. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  727. <dd>
  728. reads in the file <tt class="docutils literal"><span class="pre"><span class="Identifier">infile</span></span></tt>, performs a parallel replacement (calls <tt class="docutils literal"><span class="pre"><span class="Identifier">parallelReplace</span></span></tt>) and writes back to <tt class="docutils literal"><span class="pre"><span class="Identifier">outfile</span></span></tt>. Raises <tt class="docutils literal"><span class="pre"><span class="Identifier">IOError</span></span></tt> if an error occurs. This is supposed to be used for quick scripting.
  729. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/re.nim#L553" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  730. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/re.nim#L553" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  731. </dd>
  732. </div>
  733. </div>
  734. </dl>
  735. </div>
  736. <div class="section" id="15">
  737. <h1><a class="toc-backref" href="#15">Iterators</a></h1>
  738. <dl class="item">
  739. <div id="findAll-iterators-all">
  740. <div id="findAll.i,cstring,Regex,int,int">
  741. <dt><pre><span class="Keyword">iterator</span> <a href="#findAll.i%2Ccstring%2CRegex%2Cint%2Cint"><span class="Identifier">findAll</span></a><span class="Other">(</span><span class="Identifier">buf</span><span class="Other">:</span> <a href="system.html#cstring"><span class="Identifier">cstring</span></a><span class="Other">;</span> <span class="Identifier">pattern</span><span class="Other">:</span> <a href="re.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">bufSize</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> {.
  742. <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>
  743. <dd>
  744. <p>Yields all matching <tt class="docutils literal"><span class="pre"><span class="Identifier">substrings</span></span></tt> of <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> that match <tt class="docutils literal"><span class="pre"><span class="Identifier">pattern</span></span></tt>.</p>
  745. <p>Note that since this is an iterator you should not modify the string you are iterating over: bad things could happen.</p>
  746. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/re.nim#L426" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  747. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/re.nim#L426" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  748. </dd>
  749. </div>
  750. <div id="findAll.i,string,Regex,int">
  751. <dt><pre><span class="Keyword">iterator</span> <a href="#findAll.i%2Cstring%2CRegex%2Cint"><span class="Identifier">findAll</span></a><span class="Other">(</span><span class="Identifier">s</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="re.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="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>
  752. <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>
  753. <dd>
  754. <p>Yields all matching <em>substrings</em> of <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> that match <tt class="docutils literal"><span class="pre"><span class="Identifier">pattern</span></span></tt>.</p>
  755. <p>Note that since this is an iterator you should not modify the string you are iterating over: bad things could happen.</p>
  756. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/re.nim#L407" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  757. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/re.nim#L407" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  758. </dd>
  759. </div>
  760. </div>
  761. <div id="split-iterators-all">
  762. <div id="split.i,string,Regex,int">
  763. <dt><pre><span class="Keyword">iterator</span> <a href="#split.i%2Cstring%2CRegex%2Cint"><span class="Identifier">split</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">sep</span><span class="Other">:</span> <a href="re.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="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>
  764. <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>
  765. <dd>
  766. <p>Splits the string <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> into substrings.</p>
  767. <p>Substrings are separated by the regular expression <tt class="docutils literal"><span class="pre"><span class="Identifier">sep</span></span></tt> (and the portion matched by <tt class="docutils literal"><span class="pre"><span class="Identifier">sep</span></span></tt> is not returned).</p>
  768. <p><strong class="examples_text">Example:</strong></p>
  769. <pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">sequtils</span>
  770. <span class="Identifier">doAssert</span> <span class="Identifier">toSeq</span><span class="Punctuation">(</span><span class="Identifier">split</span><span class="Punctuation">(</span><span class="StringLit">&quot;00232this02939is39an22example111&quot;</span><span class="Punctuation">,</span> <span class="RawData">re&quot;\d+&quot;</span><span class="Punctuation">)</span><span class="Punctuation">)</span> <span class="Operator">==</span>
  771. <span class="Operator">@</span><span class="Punctuation">[</span><span class="StringLit">&quot;&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;this&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;is&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;an&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;example&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;&quot;</span><span class="Punctuation">]</span></pre>
  772. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/re.nim#L561" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  773. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/re.nim#L561" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  774. </dd>
  775. </div>
  776. </div>
  777. </dl>
  778. </div>
  779. <div class="section" id="18">
  780. <h1><a class="toc-backref" href="#18">Templates</a></h1>
  781. <dl class="item">
  782. <div id="=~-templates-all">
  783. <div id="=~.t,string,Regex">
  784. <dt><pre><span class="Keyword">template</span> <a href="#%3D~.t%2Cstring%2CRegex"><span class="Identifier">`=~`</span></a><span class="Other">(</span><span class="Identifier">s</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="re.html#Regex"><span class="Identifier">Regex</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#untyped"><span class="Identifier">untyped</span></a></pre></dt>
  785. <dd>
  786. This calls <tt class="docutils literal"><span class="pre"><span class="Identifier">match</span></span></tt> with an implicit declared <tt class="docutils literal"><span class="pre"><span class="Identifier">matches</span></span></tt> array that can be used in the scope of the <tt class="docutils literal"><span class="pre"><span class="Operator">=~</span></span></tt> call:
  787. <p><strong class="examples_text">Example:</strong></p>
  788. <pre class="listing"><span class="Keyword">proc</span> <span class="Identifier">parse</span><span class="Punctuation">(</span><span class="Identifier">line</span><span class="Punctuation">:</span> <span class="Identifier">string</span><span class="Punctuation">)</span><span class="Punctuation">:</span> <span class="Identifier">string</span> <span class="Operator">=</span>
  789. <span class="Keyword">if</span> <span class="Identifier">line</span> <span class="Operator">=~</span> <span class="RawData">re&quot;\s*(\w+)\s*\=\s*(\w+)&quot;</span><span class="Punctuation">:</span> <span class="Comment"># matches a key=value pair:</span>
  790. <span class="Identifier">result</span> <span class="Operator">=</span> <span class="Operator">$</span><span class="Punctuation">(</span><span class="Identifier">matches</span><span class="Punctuation">[</span><span class="DecNumber">0</span><span class="Punctuation">]</span><span class="Punctuation">,</span> <span class="Identifier">matches</span><span class="Punctuation">[</span><span class="DecNumber">1</span><span class="Punctuation">]</span><span class="Punctuation">)</span>
  791. <span class="Keyword">elif</span> <span class="Identifier">line</span> <span class="Operator">=~</span> <span class="RawData">re&quot;\s*(\#.*)&quot;</span><span class="Punctuation">:</span> <span class="Comment"># matches a comment</span>
  792. <span class="Comment"># note that the implicit `matches` array is different from 1st branch</span>
  793. <span class="Identifier">result</span> <span class="Operator">=</span> <span class="Operator">$</span><span class="Punctuation">(</span><span class="Identifier">matches</span><span class="Punctuation">[</span><span class="DecNumber">0</span><span class="Punctuation">]</span><span class="Punctuation">,</span><span class="Punctuation">)</span>
  794. <span class="Keyword">else</span><span class="Punctuation">:</span> <span class="Identifier">raiseAssert</span> <span class="StringLit">&quot;unreachable&quot;</span>
  795. <span class="Identifier">doAssert</span> <span class="Keyword">not</span> <span class="Identifier">declared</span><span class="Punctuation">(</span><span class="Identifier">matches</span><span class="Punctuation">)</span>
  796. <span class="Identifier">doAssert</span> <span class="Identifier">parse</span><span class="Punctuation">(</span><span class="StringLit">&quot;NAME = LENA&quot;</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="LongStringLit">&quot;&quot;&quot;(&quot;NAME&quot;, &quot;LENA&quot;)&quot;&quot;&quot;</span>
  797. <span class="Identifier">doAssert</span> <span class="Identifier">parse</span><span class="Punctuation">(</span><span class="StringLit">&quot; # comment ... &quot;</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="LongStringLit">&quot;&quot;&quot;(&quot;# comment ... &quot;,)&quot;&quot;&quot;</span></pre>
  798. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/impure/re.nim#L453" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  799. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/impure/re.nim#L453" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  800. </dd>
  801. </div>
  802. </div>
  803. </dl>
  804. </div>
  805. </div>
  806. </div>
  807. <div class="twelve-columns footer">
  808. <span class="nim-sprite"></span>
  809. <br>
  810. <small style="color: var(--hint);">Made with Nim. Generated: 2025-02-06 22:27:43 UTC</small>
  811. </div>
  812. </div>
  813. </div>
  814. <script defer data-domain="nim-lang.org" src="https://plausible.io/js/plausible.js"></script>
  815. </body>
  816. </html>