re51.html 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  5. <title>&lt;GRegex&gt;: </title>
  6. <meta name="generator" content="DocBook XSL Stylesheets V1.79.2">
  7. <link rel="home" href="index.html" title="">
  8. <link rel="up" href="ch01.html" title="GLib">
  9. <link rel="prev" href="re50.html" title="&lt;GPtrArray&gt;">
  10. <link rel="next" href="re52.html" title="&lt;%GLibRegexCompileFlags&gt;">
  11. <meta name="generator" content="GTK-Doc V1.33.1 (XML mode)">
  12. <link rel="stylesheet" href="style.css" type="text/css">
  13. </head>
  14. <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
  15. <table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="5"><tr valign="middle">
  16. <td width="100%" align="left" class="shortcuts"></td>
  17. <td><a accesskey="h" href="index.html"><img src="home.png" width="16" height="16" border="0" alt="Home"></a></td>
  18. <td><img src="up-insensitive.png" width="16" height="16" border="0"></td>
  19. <td><a accesskey="p" href="re50.html"><img src="left.png" width="16" height="16" border="0" alt="Prev"></a></td>
  20. <td><a accesskey="n" href="re52.html"><img src="right.png" width="16" height="16" border="0" alt="Next"></a></td>
  21. </tr></table>
  22. <div class="refentry">
  23. <a name="id-1.1.52"></a><div class="titlepage"></div>
  24. <div class="refnamediv">
  25. <h2>&lt;GRegex&gt;</h2>
  26. <p>&lt;GRegex&gt;</p>
  27. </div>
  28. <div class="refsect1">
  29. <a name="id-1.1.52.2"></a><h2>Description</h2>
  30. <p>The g_regex_*() functions implement regular
  31. expression pattern matching using syntax and semantics similar to
  32. Perl regular expression.
  33. </p>
  34. <p>Some functions accept a <em class="parameter"><code>start_position</code></em> argument, setting it differs
  35. from just passing over a shortened string and setting <span class="type">G_REGEX_MATCH_NOTBOL</span>
  36. in the case of a pattern that begins with any kind of lookbehind assertion.
  37. For example, consider the pattern "\Biss\B" which finds occurrences of "iss"
  38. in the middle of words. ("\B" matches only if the current position in the
  39. subject is not a word boundary.) When applied to the string "Mississipi"
  40. from the fourth byte, namely "issipi", it does not match, because "\B" is
  41. always false at the start of the subject, which is deemed to be a word
  42. boundary. However, if the entire string is passed , but with
  43. <em class="parameter"><code>start_position</code></em> set to 4, it finds the second occurrence of "iss" because
  44. it is able to look behind the starting point to discover that it is
  45. preceded by a letter.
  46. </p>
  47. <p>Note that, unless you set the <span class="type">G_REGEX_RAW</span> flag, all the strings passed
  48. to these functions must be encoded in UTF-8. The lengths and the positions
  49. inside the strings are in bytes and not in characters, so, for instance,
  50. "\xc3\xa0" (i.e. "à") is two bytes long but it is treated as a
  51. single character. If you set <span class="type">G_REGEX_RAW</span> the strings can be non-valid
  52. UTF-8 strings and a byte is treated as a character, so "\xc3\xa0" is two
  53. bytes and two characters long.
  54. </p>
  55. <p>When matching a pattern, "\n" matches only against a "\n" character in
  56. the string, and "\r" matches only a "\r" character. To match any newline
  57. sequence use "\R". This particular group matches either the two-character
  58. sequence CR + LF ("\r\n"), or one of the single characters LF (linefeed,
  59. U+000A, "\n"), VT vertical tab, U+000B, "\v"), FF (formfeed, U+000C, "\f"),
  60. CR (carriage return, U+000D, "\r"), NEL (next line, U+0085), LS (line
  61. separator, U+2028), or PS (paragraph separator, U+2029).
  62. </p>
  63. <p>The behaviour of the dot, circumflex, and dollar metacharacters are
  64. affected by newline characters, the default is to recognize any newline
  65. character (the same characters recognized by "\R"). This can be changed
  66. with <span class="type">G_REGEX_NEWLINE_CR</span>, <span class="type">G_REGEX_NEWLINE_LF</span> and <span class="type">G_REGEX_NEWLINE_CRLF</span>
  67. compile options, and with <span class="type">G_REGEX_MATCH_NEWLINE_ANY</span>,
  68. <span class="type">G_REGEX_MATCH_NEWLINE_CR</span>, <span class="type">G_REGEX_MATCH_NEWLINE_LF</span> and
  69. <span class="type">G_REGEX_MATCH_NEWLINE_CRLF</span> match options. These settings are also
  70. relevant when compiling a pattern if <span class="type">G_REGEX_EXTENDED</span> is set, and an
  71. unescaped "#" outside a character class is encountered. This indicates
  72. a comment that lasts until after the next newline.
  73. </p>
  74. <p>When setting the <code class="constant">G_REGEX_JAVASCRIPT_COMPAT</code> flag, pattern syntax and pattern
  75. matching is changed to be compatible with the way that regular expressions
  76. work in JavaScript. More precisely, a lonely ']' character in the pattern
  77. is a syntax error; the '\x' escape only allows 0 to 2 hexadecimal digits, and
  78. you must use the '\u' escape sequence with 4 hex digits to specify a unicode
  79. codepoint instead of '\x' or 'x{....}'. If '\x' or '\u' are not followed by
  80. the specified number of hex digits, they match 'x' and 'u' literally; also
  81. '\U' always matches 'U' instead of being an error in the pattern. Finally,
  82. pattern matching is modified so that back references to an unset subpattern
  83. group produces a match with the empty string instead of an error. See
  84. pcreapi(3) for more information.
  85. </p>
  86. <p>Creating and manipulating the same <span class="type">GRegex</span> structure from different
  87. threads is not a problem as <span class="type">GRegex</span> does not modify its internal
  88. state between creation and destruction, on the other hand <span class="type">GMatchInfo</span>
  89. is not threadsafe.
  90. </p>
  91. <p>The regular expressions low-level functionalities are obtained through
  92. the excellent
  93. [PCRE](http://www.pcre.org/)
  94. library written by Philip Hazel.</p>
  95. </div>
  96. <div class="refsect1">
  97. <a name="id-1.1.52.3"></a><h2>Functions</h2>
  98. <div class="refsect2">
  99. <a name="id-1.1.52.3.2"></a><h3>get-capture-count</h3>
  100. <div class="informalexample"><pre class="programlisting">(define-values (%return) (regex:get-capture-count self))
  101. </pre></div>
  102. <p>Returns the number of capturing subpatterns in the pattern.</p>
  103. <div class="refsect3">
  104. <a name="id-1.1.52.3.2.4"></a><h4>Parameters</h4>
  105. <div class="informaltable"><table><tr>
  106. <td class="parameter_name"><p>regex</p></td>
  107. <td class="parameter_description">
  108. <p>a <span class="type">GRegex</span></p>
  109. <p>Passed as <code class="code">self</code></p>
  110. </td>
  111. </tr></table></div>
  112. </div>
  113. </div>
  114. <div class="refsect2">
  115. <a name="id-1.1.52.3.3"></a><h3>get-compile-flags</h3>
  116. <div class="informalexample"><pre class="programlisting">(define-values (%return) (regex:get-compile-flags self))
  117. </pre></div>
  118. <p>Returns the compile options that <em class="parameter"><code>regex</code></em> was created with.
  119. </p>
  120. <p>Depending on the version of PCRE that is used, this may or may not
  121. include flags set by option expressions such as <code class="code">(?i)</code> found at the
  122. top-level within the compiled pattern.</p>
  123. <div class="refsect3">
  124. <a name="id-1.1.52.3.3.5"></a><h4>Parameters</h4>
  125. <div class="informaltable"><table><tr>
  126. <td class="parameter_name"><p>regex</p></td>
  127. <td class="parameter_description">
  128. <p>a <span class="type">GRegex</span></p>
  129. <p>Passed as <code class="code">self</code></p>
  130. </td>
  131. </tr></table></div>
  132. </div>
  133. </div>
  134. <div class="refsect2">
  135. <a name="id-1.1.52.3.4"></a><h3>get-has-cr-or-lf?</h3>
  136. <div class="informalexample"><pre class="programlisting">(define-values (%return) (regex:get-has-cr-or-lf? self))
  137. </pre></div>
  138. <p>Checks whether the pattern contains explicit CR or LF references.</p>
  139. <div class="refsect3">
  140. <a name="id-1.1.52.3.4.4"></a><h4>Parameters</h4>
  141. <div class="informaltable"><table><tr>
  142. <td class="parameter_name"><p>regex</p></td>
  143. <td class="parameter_description">
  144. <p>a <span class="type">GRegex</span> structure</p>
  145. <p>Passed as <code class="code">self</code></p>
  146. </td>
  147. </tr></table></div>
  148. </div>
  149. </div>
  150. <div class="refsect2">
  151. <a name="id-1.1.52.3.5"></a><h3>get-match-flags</h3>
  152. <div class="informalexample"><pre class="programlisting">(define-values (%return) (regex:get-match-flags self))
  153. </pre></div>
  154. <p>Returns the match options that <em class="parameter"><code>regex</code></em> was created with.</p>
  155. <div class="refsect3">
  156. <a name="id-1.1.52.3.5.4"></a><h4>Parameters</h4>
  157. <div class="informaltable"><table><tr>
  158. <td class="parameter_name"><p>regex</p></td>
  159. <td class="parameter_description">
  160. <p>a <span class="type">GRegex</span></p>
  161. <p>Passed as <code class="code">self</code></p>
  162. </td>
  163. </tr></table></div>
  164. </div>
  165. </div>
  166. <div class="refsect2">
  167. <a name="id-1.1.52.3.6"></a><h3>get-max-backref</h3>
  168. <div class="informalexample"><pre class="programlisting">(define-values (%return) (regex:get-max-backref self))
  169. </pre></div>
  170. <p>Returns the number of the highest back reference
  171. in the pattern, or 0 if the pattern does not contain
  172. back references.</p>
  173. <div class="refsect3">
  174. <a name="id-1.1.52.3.6.4"></a><h4>Parameters</h4>
  175. <div class="informaltable"><table><tr>
  176. <td class="parameter_name"><p>regex</p></td>
  177. <td class="parameter_description">
  178. <p>a <span class="type">GRegex</span></p>
  179. <p>Passed as <code class="code">self</code></p>
  180. </td>
  181. </tr></table></div>
  182. </div>
  183. </div>
  184. <div class="refsect2">
  185. <a name="id-1.1.52.3.7"></a><h3>get-max-lookbehind</h3>
  186. <div class="informalexample"><pre class="programlisting">(define-values (%return) (regex:get-max-lookbehind self))
  187. </pre></div>
  188. <p>Gets the number of characters in the longest lookbehind assertion in the
  189. pattern. This information is useful when doing multi-segment matching using
  190. the partial matching facilities.</p>
  191. <div class="refsect3">
  192. <a name="id-1.1.52.3.7.4"></a><h4>Parameters</h4>
  193. <div class="informaltable"><table><tr>
  194. <td class="parameter_name"><p>regex</p></td>
  195. <td class="parameter_description">
  196. <p>a <span class="type">GRegex</span> structure</p>
  197. <p>Passed as <code class="code">self</code></p>
  198. </td>
  199. </tr></table></div>
  200. </div>
  201. </div>
  202. <div class="refsect2">
  203. <a name="id-1.1.52.3.8"></a><h3>get-pattern</h3>
  204. <div class="informalexample"><pre class="programlisting">(define-values (%return) (regex:get-pattern self))
  205. </pre></div>
  206. <p>Gets the pattern string associated with <em class="parameter"><code>regex</code></em>, i.e. a copy of
  207. the string passed to <code class="function">g_regex_new()</code>.</p>
  208. <div class="refsect3">
  209. <a name="id-1.1.52.3.8.4"></a><h4>Parameters</h4>
  210. <div class="informaltable"><table><tr>
  211. <td class="parameter_name"><p>regex</p></td>
  212. <td class="parameter_description">
  213. <p>a <span class="type">GRegex</span> structure</p>
  214. <p>Passed as <code class="code">self</code></p>
  215. </td>
  216. </tr></table></div>
  217. </div>
  218. </div>
  219. <div class="refsect2">
  220. <a name="id-1.1.52.3.9"></a><h3>get-string-number</h3>
  221. <div class="informalexample"><pre class="programlisting">(define-values (%return) (regex:get-string-number self name))
  222. </pre></div>
  223. <p>Retrieves the number of the subexpression named <em class="parameter"><code>name</code></em>.</p>
  224. <div class="refsect3">
  225. <a name="id-1.1.52.3.9.4"></a><h4>Parameters</h4>
  226. <div class="informaltable"><table>
  227. <tr>
  228. <td class="parameter_name"><p>regex</p></td>
  229. <td class="parameter_description">
  230. <p><span class="type">GRegex</span> structure</p>
  231. <p>Passed as <code class="code">self</code></p>
  232. </td>
  233. </tr>
  234. <tr>
  235. <td class="parameter_name"><p>name</p></td>
  236. <td class="parameter_description">
  237. <p>name of the subexpression</p>
  238. <p>Passed as <code class="code">name</code></p>
  239. </td>
  240. </tr>
  241. </table></div>
  242. </div>
  243. </div>
  244. <div class="refsect2">
  245. <a name="id-1.1.52.3.10"></a><h3>match</h3>
  246. <div class="informalexample"><pre class="programlisting">(define-values (%return match-info) (regex:match self string match-options))
  247. </pre></div>
  248. <p>Scans for a match in <em class="parameter"><code>string</code></em> for the pattern in <em class="parameter"><code>regex</code></em>.
  249. The <em class="parameter"><code>match_options</code></em> are combined with the match options specified
  250. when the <em class="parameter"><code>regex</code></em> structure was created, letting you have more
  251. flexibility in reusing <span class="type">GRegex</span> structures.
  252. </p>
  253. <p>Unless <code class="constant">G_REGEX_RAW</code> is specified in the options, <em class="parameter"><code>string</code></em> must be valid UTF-8.
  254. </p>
  255. <p>A <span class="type">GMatchInfo</span> structure, used to get information on the match,
  256. is stored in <em class="parameter"><code>match_info</code></em> if not <code class="constant">NULL</code>. Note that if <em class="parameter"><code>match_info</code></em>
  257. is not <code class="constant">NULL</code> then it is created even if the function returns <code class="constant">FALSE</code>,
  258. i.e. you must free it regardless if regular expression actually matched.
  259. </p>
  260. <p>To retrieve all the non-overlapping matches of the pattern in
  261. string you can use <code class="function">g_match_info_next()</code>.
  262. </p>
  263. <div class="informalexample"><pre class="programlisting">
  264. static void
  265. print_uppercase_words (const gchar *string)
  266. {
  267. // Print all uppercase-only words.
  268. GRegex *regex;
  269. GMatchInfo *match_info;
  270. regex = g_regex_new ("[A-Z]+", 0, 0, NULL);
  271. g_regex_match (regex, string, 0, &amp;match_info);
  272. while (g_match_info_matches (match_info))
  273. {
  274. gchar *word = g_match_info_fetch (match_info, 0);
  275. g_print ("Found: %s\n", word);
  276. g_free (word);
  277. g_match_info_next (match_info, NULL);
  278. }
  279. g_match_info_free (match_info);
  280. g_regex_unref (regex);
  281. }
  282. </pre></div>
  283. <p><em class="parameter"><code>string</code></em> is not copied and is used in <span class="type">GMatchInfo</span> internally. If
  284. you use any <span class="type">GMatchInfo</span> method (except <code class="function">g_match_info_free()</code>) after
  285. freeing or modifying <em class="parameter"><code>string</code></em> then the behaviour is undefined.</p>
  286. <div class="refsect3">
  287. <a name="id-1.1.52.3.10.9"></a><h4>Parameters</h4>
  288. <div class="informaltable"><table>
  289. <tr>
  290. <td class="parameter_name"><p>regex</p></td>
  291. <td class="parameter_description">
  292. <p>a <span class="type">GRegex</span> structure from <code class="function">g_regex_new()</code></p>
  293. <p>Passed as <code class="code">self</code></p>
  294. </td>
  295. </tr>
  296. <tr>
  297. <td class="parameter_name"><p>string</p></td>
  298. <td class="parameter_description">
  299. <p>the string to scan for matches</p>
  300. <p>Passed as <code class="code">string</code></p>
  301. </td>
  302. </tr>
  303. <tr>
  304. <td class="parameter_name"><p>match_options</p></td>
  305. <td class="parameter_description">
  306. <p>match options</p>
  307. <p>Passed as <code class="code">match-options</code></p>
  308. </td>
  309. </tr>
  310. <tr>
  311. <td class="parameter_name"><p>match_info</p></td>
  312. <td class="parameter_description">
  313. <p>pointer to location where to store
  314. the <span class="type">GMatchInfo</span>, or <code class="constant">NULL</code> if you do not need it</p>
  315. <p>Passed as <code class="code">match-info</code></p>
  316. </td>
  317. </tr>
  318. </table></div>
  319. </div>
  320. </div>
  321. <div class="refsect2">
  322. <a name="id-1.1.52.3.11"></a><h3>match-all</h3>
  323. <div class="informalexample"><pre class="programlisting">(define-values
  324. (%return match-info)
  325. (regex:match-all self string match-options))
  326. </pre></div>
  327. <p>Using the standard algorithm for regular expression matching only
  328. the longest match in the string is retrieved. This function uses
  329. a different algorithm so it can retrieve all the possible matches.
  330. For more documentation see <code class="function">g_regex_match_all_full()</code>.
  331. </p>
  332. <p>A <span class="type">GMatchInfo</span> structure, used to get information on the match, is
  333. stored in <em class="parameter"><code>match_info</code></em> if not <code class="constant">NULL</code>. Note that if <em class="parameter"><code>match_info</code></em> is
  334. not <code class="constant">NULL</code> then it is created even if the function returns <code class="constant">FALSE</code>,
  335. i.e. you must free it regardless if regular expression actually
  336. matched.
  337. </p>
  338. <p><em class="parameter"><code>string</code></em> is not copied and is used in <span class="type">GMatchInfo</span> internally. If
  339. you use any <span class="type">GMatchInfo</span> method (except <code class="function">g_match_info_free()</code>) after
  340. freeing or modifying <em class="parameter"><code>string</code></em> then the behaviour is undefined.</p>
  341. <div class="refsect3">
  342. <a name="id-1.1.52.3.11.6"></a><h4>Parameters</h4>
  343. <div class="informaltable"><table>
  344. <tr>
  345. <td class="parameter_name"><p>regex</p></td>
  346. <td class="parameter_description">
  347. <p>a <span class="type">GRegex</span> structure from <code class="function">g_regex_new()</code></p>
  348. <p>Passed as <code class="code">self</code></p>
  349. </td>
  350. </tr>
  351. <tr>
  352. <td class="parameter_name"><p>string</p></td>
  353. <td class="parameter_description">
  354. <p>the string to scan for matches</p>
  355. <p>Passed as <code class="code">string</code></p>
  356. </td>
  357. </tr>
  358. <tr>
  359. <td class="parameter_name"><p>match_options</p></td>
  360. <td class="parameter_description">
  361. <p>match options</p>
  362. <p>Passed as <code class="code">match-options</code></p>
  363. </td>
  364. </tr>
  365. <tr>
  366. <td class="parameter_name"><p>match_info</p></td>
  367. <td class="parameter_description">
  368. <p>pointer to location where to store
  369. the <span class="type">GMatchInfo</span>, or <code class="constant">NULL</code> if you do not need it</p>
  370. <p>Passed as <code class="code">match-info</code></p>
  371. </td>
  372. </tr>
  373. </table></div>
  374. </div>
  375. </div>
  376. <div class="refsect2">
  377. <a name="id-1.1.52.3.12"></a><h3>match-all-full</h3>
  378. <div class="informalexample"><pre class="programlisting">(define-values
  379. (%return match-info)
  380. (regex:match-all-full self string start-position match-options))
  381. </pre></div>
  382. <p>Using the standard algorithm for regular expression matching only
  383. the longest match in the <em class="parameter"><code>string</code></em> is retrieved, it is not possible
  384. to obtain all the available matches. For instance matching
  385. "&lt;a&gt; &lt;b&gt; &lt;c&gt;" against the pattern "&lt;.*&gt;"
  386. you get "&lt;a&gt; &lt;b&gt; &lt;c&gt;".
  387. </p>
  388. <p>This function uses a different algorithm (called DFA, i.e. deterministic
  389. finite automaton), so it can retrieve all the possible matches, all
  390. starting at the same point in the string. For instance matching
  391. "&lt;a&gt; &lt;b&gt; &lt;c&gt;" against the pattern "&lt;.*&gt;;"
  392. you would obtain three matches: "&lt;a&gt; &lt;b&gt; &lt;c&gt;",
  393. "&lt;a&gt; &lt;b&gt;" and "&lt;a&gt;".
  394. </p>
  395. <p>The number of matched strings is retrieved using
  396. <code class="function">g_match_info_get_match_count()</code>. To obtain the matched strings and
  397. their position you can use, respectively, <code class="function">g_match_info_fetch()</code> and
  398. <code class="function">g_match_info_fetch_pos()</code>. Note that the strings are returned in
  399. reverse order of length; that is, the longest matching string is
  400. given first.
  401. </p>
  402. <p>Note that the DFA algorithm is slower than the standard one and it
  403. is not able to capture substrings, so backreferences do not work.
  404. </p>
  405. <p>Setting <em class="parameter"><code>start_position</code></em> differs from just passing over a shortened
  406. string and setting <span class="type">G_REGEX_MATCH_NOTBOL</span> in the case of a pattern
  407. that begins with any kind of lookbehind assertion, such as "\b".
  408. </p>
  409. <p>Unless <code class="constant">G_REGEX_RAW</code> is specified in the options, <em class="parameter"><code>string</code></em> must be valid UTF-8.
  410. </p>
  411. <p>A <span class="type">GMatchInfo</span> structure, used to get information on the match, is
  412. stored in <em class="parameter"><code>match_info</code></em> if not <code class="constant">NULL</code>. Note that if <em class="parameter"><code>match_info</code></em> is
  413. not <code class="constant">NULL</code> then it is created even if the function returns <code class="constant">FALSE</code>,
  414. i.e. you must free it regardless if regular expression actually
  415. matched.
  416. </p>
  417. <p><em class="parameter"><code>string</code></em> is not copied and is used in <span class="type">GMatchInfo</span> internally. If
  418. you use any <span class="type">GMatchInfo</span> method (except <code class="function">g_match_info_free()</code>) after
  419. freeing or modifying <em class="parameter"><code>string</code></em> then the behaviour is undefined.</p>
  420. <div class="refsect3">
  421. <a name="id-1.1.52.3.12.11"></a><h4>Parameters</h4>
  422. <div class="informaltable"><table>
  423. <tr>
  424. <td class="parameter_name"><p>regex</p></td>
  425. <td class="parameter_description">
  426. <p>a <span class="type">GRegex</span> structure from <code class="function">g_regex_new()</code></p>
  427. <p>Passed as <code class="code">self</code></p>
  428. </td>
  429. </tr>
  430. <tr>
  431. <td class="parameter_name"><p>string</p></td>
  432. <td class="parameter_description">
  433. <p>the string to scan for matches</p>
  434. <p>Passed as <code class="code">string</code></p>
  435. </td>
  436. </tr>
  437. <tr>
  438. <td class="parameter_name"><p>string_len</p></td>
  439. <td class="parameter_description">
  440. <p>the length of <em class="parameter"><code>string</code></em>, in bytes, or -1 if <em class="parameter"><code>string</code></em> is nul-terminated</p>
  441. <p>Inferred from <code class="code">string</code></p>
  442. </td>
  443. </tr>
  444. <tr>
  445. <td class="parameter_name"><p>start_position</p></td>
  446. <td class="parameter_description">
  447. <p>starting index of the string to match, in bytes</p>
  448. <p>Passed as <code class="code">start-position</code></p>
  449. </td>
  450. </tr>
  451. <tr>
  452. <td class="parameter_name"><p>match_options</p></td>
  453. <td class="parameter_description">
  454. <p>match options</p>
  455. <p>Passed as <code class="code">match-options</code></p>
  456. </td>
  457. </tr>
  458. <tr>
  459. <td class="parameter_name"><p>match_info</p></td>
  460. <td class="parameter_description">
  461. <p>pointer to location where to store
  462. the <span class="type">GMatchInfo</span>, or <code class="constant">NULL</code> if you do not need it</p>
  463. <p>Passed as <code class="code">match-info</code></p>
  464. </td>
  465. </tr>
  466. </table></div>
  467. </div>
  468. </div>
  469. <div class="refsect2">
  470. <a name="id-1.1.52.3.13"></a><h3>match-full</h3>
  471. <div class="informalexample"><pre class="programlisting">(define-values
  472. (%return match-info)
  473. (regex:match-full self string start-position match-options))
  474. </pre></div>
  475. <p>Scans for a match in <em class="parameter"><code>string</code></em> for the pattern in <em class="parameter"><code>regex</code></em>.
  476. The <em class="parameter"><code>match_options</code></em> are combined with the match options specified
  477. when the <em class="parameter"><code>regex</code></em> structure was created, letting you have more
  478. flexibility in reusing <span class="type">GRegex</span> structures.
  479. </p>
  480. <p>Setting <em class="parameter"><code>start_position</code></em> differs from just passing over a shortened
  481. string and setting <span class="type">G_REGEX_MATCH_NOTBOL</span> in the case of a pattern
  482. that begins with any kind of lookbehind assertion, such as "\b".
  483. </p>
  484. <p>Unless <code class="constant">G_REGEX_RAW</code> is specified in the options, <em class="parameter"><code>string</code></em> must be valid UTF-8.
  485. </p>
  486. <p>A <span class="type">GMatchInfo</span> structure, used to get information on the match, is
  487. stored in <em class="parameter"><code>match_info</code></em> if not <code class="constant">NULL</code>. Note that if <em class="parameter"><code>match_info</code></em> is
  488. not <code class="constant">NULL</code> then it is created even if the function returns <code class="constant">FALSE</code>,
  489. i.e. you must free it regardless if regular expression actually
  490. matched.
  491. </p>
  492. <p><em class="parameter"><code>string</code></em> is not copied and is used in <span class="type">GMatchInfo</span> internally. If
  493. you use any <span class="type">GMatchInfo</span> method (except <code class="function">g_match_info_free()</code>) after
  494. freeing or modifying <em class="parameter"><code>string</code></em> then the behaviour is undefined.
  495. </p>
  496. <p>To retrieve all the non-overlapping matches of the pattern in
  497. string you can use <code class="function">g_match_info_next()</code>.
  498. </p>
  499. <div class="informalexample"><pre class="programlisting">
  500. static void
  501. print_uppercase_words (const gchar *string)
  502. {
  503. // Print all uppercase-only words.
  504. GRegex *regex;
  505. GMatchInfo *match_info;
  506. GError *error = NULL;
  507. regex = g_regex_new ("[A-Z]+", 0, 0, NULL);
  508. g_regex_match_full (regex, string, -1, 0, 0, &amp;match_info, &amp;error);
  509. while (g_match_info_matches (match_info))
  510. {
  511. gchar *word = g_match_info_fetch (match_info, 0);
  512. g_print ("Found: %s\n", word);
  513. g_free (word);
  514. g_match_info_next (match_info, &amp;error);
  515. }
  516. g_match_info_free (match_info);
  517. g_regex_unref (regex);
  518. if (error != NULL)
  519. {
  520. g_printerr ("Error while matching: %s\n", error-&gt;message);
  521. g_error_free (error);
  522. }
  523. }
  524. </pre></div>
  525. <div class="refsect3">
  526. <a name="id-1.1.52.3.13.10"></a><h4>Parameters</h4>
  527. <div class="informaltable"><table>
  528. <tr>
  529. <td class="parameter_name"><p>regex</p></td>
  530. <td class="parameter_description">
  531. <p>a <span class="type">GRegex</span> structure from <code class="function">g_regex_new()</code></p>
  532. <p>Passed as <code class="code">self</code></p>
  533. </td>
  534. </tr>
  535. <tr>
  536. <td class="parameter_name"><p>string</p></td>
  537. <td class="parameter_description">
  538. <p>the string to scan for matches</p>
  539. <p>Passed as <code class="code">string</code></p>
  540. </td>
  541. </tr>
  542. <tr>
  543. <td class="parameter_name"><p>string_len</p></td>
  544. <td class="parameter_description">
  545. <p>the length of <em class="parameter"><code>string</code></em>, in bytes, or -1 if <em class="parameter"><code>string</code></em> is nul-terminated</p>
  546. <p>Inferred from <code class="code">string</code></p>
  547. </td>
  548. </tr>
  549. <tr>
  550. <td class="parameter_name"><p>start_position</p></td>
  551. <td class="parameter_description">
  552. <p>starting index of the string to match, in bytes</p>
  553. <p>Passed as <code class="code">start-position</code></p>
  554. </td>
  555. </tr>
  556. <tr>
  557. <td class="parameter_name"><p>match_options</p></td>
  558. <td class="parameter_description">
  559. <p>match options</p>
  560. <p>Passed as <code class="code">match-options</code></p>
  561. </td>
  562. </tr>
  563. <tr>
  564. <td class="parameter_name"><p>match_info</p></td>
  565. <td class="parameter_description">
  566. <p>pointer to location where to store
  567. the <span class="type">GMatchInfo</span>, or <code class="constant">NULL</code> if you do not need it</p>
  568. <p>Passed as <code class="code">match-info</code></p>
  569. </td>
  570. </tr>
  571. </table></div>
  572. </div>
  573. </div>
  574. <div class="refsect2">
  575. <a name="id-1.1.52.3.14"></a><h3>ref</h3>
  576. <div class="informalexample"><pre class="programlisting">(define-values (%return) (regex:ref self))
  577. </pre></div>
  578. <p>Increases reference count of <em class="parameter"><code>regex</code></em> by 1.</p>
  579. <div class="refsect3">
  580. <a name="id-1.1.52.3.14.4"></a><h4>Parameters</h4>
  581. <div class="informaltable"><table><tr>
  582. <td class="parameter_name"><p>regex</p></td>
  583. <td class="parameter_description">
  584. <p>a <span class="type">GRegex</span></p>
  585. <p>Passed as <code class="code">self</code></p>
  586. </td>
  587. </tr></table></div>
  588. </div>
  589. </div>
  590. <div class="refsect2">
  591. <a name="id-1.1.52.3.15"></a><h3>replace</h3>
  592. <div class="informalexample"><pre class="programlisting">(define-values
  593. (%return)
  594. (regex:replace self string start-position replacement match-options))
  595. </pre></div>
  596. <p>Replaces all occurrences of the pattern in <em class="parameter"><code>regex</code></em> with the
  597. replacement text. Backreferences of the form '\number' or
  598. '\g&lt;number&gt;' in the replacement text are interpolated by the
  599. number-th captured subexpression of the match, '\g&lt;name&gt;' refers
  600. to the captured subexpression with the given name. '\0' refers
  601. to the complete match, but '\0' followed by a number is the octal
  602. representation of a character. To include a literal '\' in the
  603. replacement, write '\\\\'.
  604. </p>
  605. <p>There are also escapes that changes the case of the following text:
  606. </p>
  607. <p>- \l: Convert to lower case the next character
  608. - \u: Convert to upper case the next character
  609. - \L: Convert to lower case till \E
  610. - \U: Convert to upper case till \E
  611. - \E: End case modification
  612. </p>
  613. <p>If you do not need to use backreferences use <code class="function">g_regex_replace_literal()</code>.
  614. </p>
  615. <p>The <em class="parameter"><code>replacement</code></em> string must be UTF-8 encoded even if <span class="type">G_REGEX_RAW</span> was
  616. passed to <code class="function">g_regex_new()</code>. If you want to use not UTF-8 encoded strings
  617. you can use <code class="function">g_regex_replace_literal()</code>.
  618. </p>
  619. <p>Setting <em class="parameter"><code>start_position</code></em> differs from just passing over a shortened
  620. string and setting <span class="type">G_REGEX_MATCH_NOTBOL</span> in the case of a pattern that
  621. begins with any kind of lookbehind assertion, such as "\b".</p>
  622. <div class="refsect3">
  623. <a name="id-1.1.52.3.15.9"></a><h4>Parameters</h4>
  624. <div class="informaltable"><table>
  625. <tr>
  626. <td class="parameter_name"><p>regex</p></td>
  627. <td class="parameter_description">
  628. <p>a <span class="type">GRegex</span> structure</p>
  629. <p>Passed as <code class="code">self</code></p>
  630. </td>
  631. </tr>
  632. <tr>
  633. <td class="parameter_name"><p>string</p></td>
  634. <td class="parameter_description">
  635. <p>the string to perform matches against</p>
  636. <p>Passed as <code class="code">string</code></p>
  637. </td>
  638. </tr>
  639. <tr>
  640. <td class="parameter_name"><p>string_len</p></td>
  641. <td class="parameter_description">
  642. <p>the length of <em class="parameter"><code>string</code></em>, in bytes, or -1 if <em class="parameter"><code>string</code></em> is nul-terminated</p>
  643. <p>Inferred from <code class="code">string</code></p>
  644. </td>
  645. </tr>
  646. <tr>
  647. <td class="parameter_name"><p>start_position</p></td>
  648. <td class="parameter_description">
  649. <p>starting index of the string to match, in bytes</p>
  650. <p>Passed as <code class="code">start-position</code></p>
  651. </td>
  652. </tr>
  653. <tr>
  654. <td class="parameter_name"><p>replacement</p></td>
  655. <td class="parameter_description">
  656. <p>text to replace each match with</p>
  657. <p>Passed as <code class="code">replacement</code></p>
  658. </td>
  659. </tr>
  660. <tr>
  661. <td class="parameter_name"><p>match_options</p></td>
  662. <td class="parameter_description">
  663. <p>options for the match</p>
  664. <p>Passed as <code class="code">match-options</code></p>
  665. </td>
  666. </tr>
  667. </table></div>
  668. </div>
  669. </div>
  670. <div class="refsect2">
  671. <a name="id-1.1.52.3.16"></a><h3>replace-literal</h3>
  672. <div class="informalexample"><pre class="programlisting">(define-values
  673. (%return)
  674. (regex:replace-literal self string start-position replacement match-options))
  675. </pre></div>
  676. <p>Replaces all occurrences of the pattern in <em class="parameter"><code>regex</code></em> with the
  677. replacement text. <em class="parameter"><code>replacement</code></em> is replaced literally, to
  678. include backreferences use <code class="function">g_regex_replace()</code>.
  679. </p>
  680. <p>Setting <em class="parameter"><code>start_position</code></em> differs from just passing over a
  681. shortened string and setting <span class="type">G_REGEX_MATCH_NOTBOL</span> in the
  682. case of a pattern that begins with any kind of lookbehind
  683. assertion, such as "\b".</p>
  684. <div class="refsect3">
  685. <a name="id-1.1.52.3.16.5"></a><h4>Parameters</h4>
  686. <div class="informaltable"><table>
  687. <tr>
  688. <td class="parameter_name"><p>regex</p></td>
  689. <td class="parameter_description">
  690. <p>a <span class="type">GRegex</span> structure</p>
  691. <p>Passed as <code class="code">self</code></p>
  692. </td>
  693. </tr>
  694. <tr>
  695. <td class="parameter_name"><p>string</p></td>
  696. <td class="parameter_description">
  697. <p>the string to perform matches against</p>
  698. <p>Passed as <code class="code">string</code></p>
  699. </td>
  700. </tr>
  701. <tr>
  702. <td class="parameter_name"><p>string_len</p></td>
  703. <td class="parameter_description">
  704. <p>the length of <em class="parameter"><code>string</code></em>, in bytes, or -1 if <em class="parameter"><code>string</code></em> is nul-terminated</p>
  705. <p>Inferred from <code class="code">string</code></p>
  706. </td>
  707. </tr>
  708. <tr>
  709. <td class="parameter_name"><p>start_position</p></td>
  710. <td class="parameter_description">
  711. <p>starting index of the string to match, in bytes</p>
  712. <p>Passed as <code class="code">start-position</code></p>
  713. </td>
  714. </tr>
  715. <tr>
  716. <td class="parameter_name"><p>replacement</p></td>
  717. <td class="parameter_description">
  718. <p>text to replace each match with</p>
  719. <p>Passed as <code class="code">replacement</code></p>
  720. </td>
  721. </tr>
  722. <tr>
  723. <td class="parameter_name"><p>match_options</p></td>
  724. <td class="parameter_description">
  725. <p>options for the match</p>
  726. <p>Passed as <code class="code">match-options</code></p>
  727. </td>
  728. </tr>
  729. </table></div>
  730. </div>
  731. </div>
  732. <div class="refsect2">
  733. <a name="id-1.1.52.3.17"></a><h3>split</h3>
  734. <div class="informalexample"><pre class="programlisting">(define-values (%return) (regex:split self string match-options))
  735. </pre></div>
  736. <p>Breaks the string on the pattern, and returns an array of the tokens.
  737. If the pattern contains capturing parentheses, then the text for each
  738. of the substrings will also be returned. If the pattern does not match
  739. anywhere in the string, then the whole string is returned as the first
  740. token.
  741. </p>
  742. <p>As a special case, the result of splitting the empty string "" is an
  743. empty vector, not a vector containing a single string. The reason for
  744. this special case is that being able to represent an empty vector is
  745. typically more useful than consistent handling of empty elements. If
  746. you do need to represent empty elements, you'll need to check for the
  747. empty string before calling this function.
  748. </p>
  749. <p>A pattern that can match empty strings splits <em class="parameter"><code>string</code></em> into separate
  750. characters wherever it matches the empty string between characters.
  751. For example splitting "ab c" using as a separator "\s*", you will get
  752. "a", "b" and "c".</p>
  753. <div class="refsect3">
  754. <a name="id-1.1.52.3.17.6"></a><h4>Parameters</h4>
  755. <div class="informaltable"><table>
  756. <tr>
  757. <td class="parameter_name"><p>regex</p></td>
  758. <td class="parameter_description">
  759. <p>a <span class="type">GRegex</span> structure</p>
  760. <p>Passed as <code class="code">self</code></p>
  761. </td>
  762. </tr>
  763. <tr>
  764. <td class="parameter_name"><p>string</p></td>
  765. <td class="parameter_description">
  766. <p>the string to split with the pattern</p>
  767. <p>Passed as <code class="code">string</code></p>
  768. </td>
  769. </tr>
  770. <tr>
  771. <td class="parameter_name"><p>match_options</p></td>
  772. <td class="parameter_description">
  773. <p>match time option flags</p>
  774. <p>Passed as <code class="code">match-options</code></p>
  775. </td>
  776. </tr>
  777. </table></div>
  778. </div>
  779. </div>
  780. <div class="refsect2">
  781. <a name="id-1.1.52.3.18"></a><h3>split-full</h3>
  782. <div class="informalexample"><pre class="programlisting">(define-values
  783. (%return)
  784. (regex:split-full self string start-position match-options max-tokens))
  785. </pre></div>
  786. <p>Breaks the string on the pattern, and returns an array of the tokens.
  787. If the pattern contains capturing parentheses, then the text for each
  788. of the substrings will also be returned. If the pattern does not match
  789. anywhere in the string, then the whole string is returned as the first
  790. token.
  791. </p>
  792. <p>As a special case, the result of splitting the empty string "" is an
  793. empty vector, not a vector containing a single string. The reason for
  794. this special case is that being able to represent an empty vector is
  795. typically more useful than consistent handling of empty elements. If
  796. you do need to represent empty elements, you'll need to check for the
  797. empty string before calling this function.
  798. </p>
  799. <p>A pattern that can match empty strings splits <em class="parameter"><code>string</code></em> into separate
  800. characters wherever it matches the empty string between characters.
  801. For example splitting "ab c" using as a separator "\s*", you will get
  802. "a", "b" and "c".
  803. </p>
  804. <p>Setting <em class="parameter"><code>start_position</code></em> differs from just passing over a shortened
  805. string and setting <span class="type">G_REGEX_MATCH_NOTBOL</span> in the case of a pattern
  806. that begins with any kind of lookbehind assertion, such as "\b".</p>
  807. <div class="refsect3">
  808. <a name="id-1.1.52.3.18.7"></a><h4>Parameters</h4>
  809. <div class="informaltable"><table>
  810. <tr>
  811. <td class="parameter_name"><p>regex</p></td>
  812. <td class="parameter_description">
  813. <p>a <span class="type">GRegex</span> structure</p>
  814. <p>Passed as <code class="code">self</code></p>
  815. </td>
  816. </tr>
  817. <tr>
  818. <td class="parameter_name"><p>string</p></td>
  819. <td class="parameter_description">
  820. <p>the string to split with the pattern</p>
  821. <p>Passed as <code class="code">string</code></p>
  822. </td>
  823. </tr>
  824. <tr>
  825. <td class="parameter_name"><p>string_len</p></td>
  826. <td class="parameter_description">
  827. <p>the length of <em class="parameter"><code>string</code></em>, in bytes, or -1 if <em class="parameter"><code>string</code></em> is nul-terminated</p>
  828. <p>Inferred from <code class="code">string</code></p>
  829. </td>
  830. </tr>
  831. <tr>
  832. <td class="parameter_name"><p>start_position</p></td>
  833. <td class="parameter_description">
  834. <p>starting index of the string to match, in bytes</p>
  835. <p>Passed as <code class="code">start-position</code></p>
  836. </td>
  837. </tr>
  838. <tr>
  839. <td class="parameter_name"><p>match_options</p></td>
  840. <td class="parameter_description">
  841. <p>match time option flags</p>
  842. <p>Passed as <code class="code">match-options</code></p>
  843. </td>
  844. </tr>
  845. <tr>
  846. <td class="parameter_name"><p>max_tokens</p></td>
  847. <td class="parameter_description">
  848. <p>the maximum number of tokens to split <em class="parameter"><code>string</code></em> into.
  849. If this is less than 1, the string is split completely</p>
  850. <p>Passed as <code class="code">max-tokens</code></p>
  851. </td>
  852. </tr>
  853. </table></div>
  854. </div>
  855. </div>
  856. <div class="refsect2">
  857. <a name="id-1.1.52.3.19"></a><h3>unref</h3>
  858. <div class="informalexample"><pre class="programlisting">(define-values () (regex:unref self))
  859. </pre></div>
  860. <p>Decreases reference count of <em class="parameter"><code>regex</code></em> by 1. When reference count drops
  861. to zero, it frees all the memory associated with the regex structure.</p>
  862. <div class="refsect3">
  863. <a name="id-1.1.52.3.19.4"></a><h4>Parameters</h4>
  864. <div class="informaltable"><table><tr>
  865. <td class="parameter_name"><p>regex</p></td>
  866. <td class="parameter_description">
  867. <p>a <span class="type">GRegex</span></p>
  868. <p>Passed as <code class="code">self</code></p>
  869. </td>
  870. </tr></table></div>
  871. </div>
  872. </div>
  873. <div class="refsect2">
  874. <a name="id-1.1.52.3.20"></a><h3>regex:new</h3>
  875. <div class="informalexample"><pre class="programlisting">(define-values (%return) (regex:new pattern compile-options match-options))
  876. </pre></div>
  877. <p>Undocumented</p>
  878. <div class="refsect3">
  879. <a name="id-1.1.52.3.20.4"></a><h4>Parameters</h4>
  880. <div class="informaltable"><table>
  881. <tr>
  882. <td class="parameter_name"><p>pattern</p></td>
  883. <td class="parameter_description">
  884. <p></p>
  885. <p>Passed as <code class="code">pattern</code></p>
  886. </td>
  887. </tr>
  888. <tr>
  889. <td class="parameter_name"><p>compile_options</p></td>
  890. <td class="parameter_description">
  891. <p></p>
  892. <p>Passed as <code class="code">compile-options</code></p>
  893. </td>
  894. </tr>
  895. <tr>
  896. <td class="parameter_name"><p>match_options</p></td>
  897. <td class="parameter_description">
  898. <p></p>
  899. <p>Passed as <code class="code">match-options</code></p>
  900. </td>
  901. </tr>
  902. </table></div>
  903. </div>
  904. </div>
  905. <div class="refsect2">
  906. <a name="id-1.1.52.3.21"></a><h3>regex:check-replacement</h3>
  907. <div class="informalexample"><pre class="programlisting">(define-values (%return has-references) (regex:check-replacement replacement))
  908. </pre></div>
  909. <p>Checks whether <em class="parameter"><code>replacement</code></em> is a valid replacement string
  910. (see <code class="function">g_regex_replace()</code>), i.e. that all escape sequences in
  911. it are valid.
  912. </p>
  913. <p>If <em class="parameter"><code>has_references</code></em> is not <code class="constant">NULL</code> then <em class="parameter"><code>replacement</code></em> is checked
  914. for pattern references. For instance, replacement text 'foo\n'
  915. does not contain references and may be evaluated without information
  916. about actual match, but '\0\1' (whole match followed by first
  917. subpattern) requires valid <span class="type">GMatchInfo</span> object.</p>
  918. <div class="refsect3">
  919. <a name="id-1.1.52.3.21.5"></a><h4>Parameters</h4>
  920. <div class="informaltable"><table>
  921. <tr>
  922. <td class="parameter_name"><p>replacement</p></td>
  923. <td class="parameter_description">
  924. <p>the replacement string</p>
  925. <p>Passed as <code class="code">replacement</code></p>
  926. </td>
  927. </tr>
  928. <tr>
  929. <td class="parameter_name"><p>has_references</p></td>
  930. <td class="parameter_description">
  931. <p>location to store information about
  932. references in <em class="parameter"><code>replacement</code></em> or <code class="constant">NULL</code></p>
  933. <p>Passed as <code class="code">has-references</code></p>
  934. </td>
  935. </tr>
  936. </table></div>
  937. </div>
  938. </div>
  939. <div class="refsect2">
  940. <a name="id-1.1.52.3.22"></a><h3>regex:error-quark</h3>
  941. <div class="informalexample"><pre class="programlisting">(define-values (%return) (regex:error-quark))
  942. </pre></div>
  943. <p>Undocumented</p>
  944. </div>
  945. <div class="refsect2">
  946. <a name="id-1.1.52.3.23"></a><h3>regex:escape-nul</h3>
  947. <div class="informalexample"><pre class="programlisting">(define-values (%return) (regex:escape-nul string length))
  948. </pre></div>
  949. <p>Escapes the nul characters in <em class="parameter"><code>string</code></em> to "\x00". It can be used
  950. to compile a regex with embedded nul characters.
  951. </p>
  952. <p>For completeness, <em class="parameter"><code>length</code></em> can be -1 for a nul-terminated string.
  953. In this case the output string will be of course equal to <em class="parameter"><code>string</code></em>.</p>
  954. <div class="refsect3">
  955. <a name="id-1.1.52.3.23.5"></a><h4>Parameters</h4>
  956. <div class="informaltable"><table>
  957. <tr>
  958. <td class="parameter_name"><p>string</p></td>
  959. <td class="parameter_description">
  960. <p>the string to escape</p>
  961. <p>Passed as <code class="code">string</code></p>
  962. </td>
  963. </tr>
  964. <tr>
  965. <td class="parameter_name"><p>length</p></td>
  966. <td class="parameter_description">
  967. <p>the length of <em class="parameter"><code>string</code></em></p>
  968. <p>Passed as <code class="code">length</code></p>
  969. </td>
  970. </tr>
  971. </table></div>
  972. </div>
  973. </div>
  974. <div class="refsect2">
  975. <a name="id-1.1.52.3.24"></a><h3>regex:escape-string</h3>
  976. <div class="informalexample"><pre class="programlisting">(define-values (%return) (regex:escape-string string))
  977. </pre></div>
  978. <p>Escapes the special characters used for regular expressions
  979. in <em class="parameter"><code>string</code></em>, for instance "a.b*c" becomes "a\.b\*c". This
  980. function is useful to dynamically generate regular expressions.
  981. </p>
  982. <p><em class="parameter"><code>string</code></em> can contain nul characters that are replaced with "\0",
  983. in this case remember to specify the correct length of <em class="parameter"><code>string</code></em>
  984. in <em class="parameter"><code>length</code></em>.</p>
  985. <div class="refsect3">
  986. <a name="id-1.1.52.3.24.5"></a><h4>Parameters</h4>
  987. <div class="informaltable"><table>
  988. <tr>
  989. <td class="parameter_name"><p>string</p></td>
  990. <td class="parameter_description">
  991. <p>the string to escape</p>
  992. <p>Passed as <code class="code">string</code></p>
  993. </td>
  994. </tr>
  995. <tr>
  996. <td class="parameter_name"><p>length</p></td>
  997. <td class="parameter_description">
  998. <p>the length of <em class="parameter"><code>string</code></em>, in bytes, or -1 if <em class="parameter"><code>string</code></em> is nul-terminated</p>
  999. <p>Inferred from <code class="code">string</code></p>
  1000. </td>
  1001. </tr>
  1002. </table></div>
  1003. </div>
  1004. </div>
  1005. <div class="refsect2">
  1006. <a name="id-1.1.52.3.25"></a><h3>regex:match-simple?</h3>
  1007. <div class="informalexample"><pre class="programlisting">(define-values
  1008. (%return)
  1009. (regex:match-simple? pattern string compile-options match-options))
  1010. </pre></div>
  1011. <p>Scans for a match in <em class="parameter"><code>string</code></em> for <em class="parameter"><code>pattern</code></em>.
  1012. </p>
  1013. <p>This function is equivalent to <code class="function">g_regex_match()</code> but it does not
  1014. require to compile the pattern with <code class="function">g_regex_new()</code>, avoiding some
  1015. lines of code when you need just to do a match without extracting
  1016. substrings, capture counts, and so on.
  1017. </p>
  1018. <p>If this function is to be called on the same <em class="parameter"><code>pattern</code></em> more than
  1019. once, it's more efficient to compile the pattern once with
  1020. <code class="function">g_regex_new()</code> and then use <code class="function">g_regex_match()</code>.</p>
  1021. <div class="refsect3">
  1022. <a name="id-1.1.52.3.25.6"></a><h4>Parameters</h4>
  1023. <div class="informaltable"><table>
  1024. <tr>
  1025. <td class="parameter_name"><p>pattern</p></td>
  1026. <td class="parameter_description">
  1027. <p>the regular expression</p>
  1028. <p>Passed as <code class="code">pattern</code></p>
  1029. </td>
  1030. </tr>
  1031. <tr>
  1032. <td class="parameter_name"><p>string</p></td>
  1033. <td class="parameter_description">
  1034. <p>the string to scan for matches</p>
  1035. <p>Passed as <code class="code">string</code></p>
  1036. </td>
  1037. </tr>
  1038. <tr>
  1039. <td class="parameter_name"><p>compile_options</p></td>
  1040. <td class="parameter_description">
  1041. <p>compile options for the regular expression, or 0</p>
  1042. <p>Passed as <code class="code">compile-options</code></p>
  1043. </td>
  1044. </tr>
  1045. <tr>
  1046. <td class="parameter_name"><p>match_options</p></td>
  1047. <td class="parameter_description">
  1048. <p>match options, or 0</p>
  1049. <p>Passed as <code class="code">match-options</code></p>
  1050. </td>
  1051. </tr>
  1052. </table></div>
  1053. </div>
  1054. </div>
  1055. <div class="refsect2">
  1056. <a name="id-1.1.52.3.26"></a><h3>regex:split-simple</h3>
  1057. <div class="informalexample"><pre class="programlisting">(define-values
  1058. (%return)
  1059. (regex:split-simple pattern string compile-options match-options))
  1060. </pre></div>
  1061. <p>Breaks the string on the pattern, and returns an array of
  1062. the tokens. If the pattern contains capturing parentheses,
  1063. then the text for each of the substrings will also be returned.
  1064. If the pattern does not match anywhere in the string, then the
  1065. whole string is returned as the first token.
  1066. </p>
  1067. <p>This function is equivalent to <code class="function">g_regex_split()</code> but it does
  1068. not require to compile the pattern with <code class="function">g_regex_new()</code>, avoiding
  1069. some lines of code when you need just to do a split without
  1070. extracting substrings, capture counts, and so on.
  1071. </p>
  1072. <p>If this function is to be called on the same <em class="parameter"><code>pattern</code></em> more than
  1073. once, it's more efficient to compile the pattern once with
  1074. <code class="function">g_regex_new()</code> and then use <code class="function">g_regex_split()</code>.
  1075. </p>
  1076. <p>As a special case, the result of splitting the empty string ""
  1077. is an empty vector, not a vector containing a single string.
  1078. The reason for this special case is that being able to represent
  1079. an empty vector is typically more useful than consistent handling
  1080. of empty elements. If you do need to represent empty elements,
  1081. you'll need to check for the empty string before calling this
  1082. function.
  1083. </p>
  1084. <p>A pattern that can match empty strings splits <em class="parameter"><code>string</code></em> into
  1085. separate characters wherever it matches the empty string between
  1086. characters. For example splitting "ab c" using as a separator
  1087. "\s*", you will get "a", "b" and "c".</p>
  1088. <div class="refsect3">
  1089. <a name="id-1.1.52.3.26.8"></a><h4>Parameters</h4>
  1090. <div class="informaltable"><table>
  1091. <tr>
  1092. <td class="parameter_name"><p>pattern</p></td>
  1093. <td class="parameter_description">
  1094. <p>the regular expression</p>
  1095. <p>Passed as <code class="code">pattern</code></p>
  1096. </td>
  1097. </tr>
  1098. <tr>
  1099. <td class="parameter_name"><p>string</p></td>
  1100. <td class="parameter_description">
  1101. <p>the string to scan for matches</p>
  1102. <p>Passed as <code class="code">string</code></p>
  1103. </td>
  1104. </tr>
  1105. <tr>
  1106. <td class="parameter_name"><p>compile_options</p></td>
  1107. <td class="parameter_description">
  1108. <p>compile options for the regular expression, or 0</p>
  1109. <p>Passed as <code class="code">compile-options</code></p>
  1110. </td>
  1111. </tr>
  1112. <tr>
  1113. <td class="parameter_name"><p>match_options</p></td>
  1114. <td class="parameter_description">
  1115. <p>match options, or 0</p>
  1116. <p>Passed as <code class="code">match-options</code></p>
  1117. </td>
  1118. </tr>
  1119. </table></div>
  1120. </div>
  1121. </div>
  1122. </div>
  1123. </div>
  1124. <div class="footer">
  1125. <hr>Generated by GTK-Doc V1.33.1</div>
  1126. </body>
  1127. </html>