4
4
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5
5
<title>Perl-compatible regular expressions</title>
6
<meta name="generator" content="DocBook XSL Stylesheets V1.74.0">
6
<meta name="generator" content="DocBook XSL Stylesheets V1.74.2">
7
7
<link rel="home" href="index.html" title="GLib Reference Manual">
8
8
<link rel="up" href="glib-utilities.html" title="GLib Utilities">
9
9
<link rel="prev" href="glib-Glob-style-pattern-matching.html" title="Glob-style pattern matching">
27
27
<link rel="index" href="ix09.html" title="Index of new symbols in 2.14">
28
28
<link rel="index" href="ix10.html" title="Index of new symbols in 2.16">
29
29
<link rel="index" href="ix11.html" title="Index of new symbols in 2.18">
30
<link rel="index" href="ix12.html" title="Index of new symbols in 2.20">
31
32
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
32
33
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2">
826
827
<td><p><span class="term"><em class="parameter"><code>compile_options</code></em> :</span></p></td>
827
<td> compile options for the regular expression
828
<td> compile options for the regular expression, or 0
831
832
<td><p><span class="term"><em class="parameter"><code>match_options</code></em> :</span></p></td>
832
<td> match options for the regular expression
833
<td> match options for the regular expression, or 0
1085
1086
<td><p><span class="term"><em class="parameter"><code>compile_options</code></em> :</span></p></td>
1086
<td> compile options for the regular expression
1087
<td> compile options for the regular expression, or 0
1090
1091
<td><p><span class="term"><em class="parameter"><code>match_options</code></em> :</span></p></td>
1092
<td> match options, or 0
1095
1096
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
1096
<td> <a class="link" href="glib-Standard-Macros.html#TRUE--CAPS" title="TRUE"><code class="literal">TRUE</code></a> is the string matched, <a class="link" href="glib-Standard-Macros.html#FALSE--CAPS" title="FALSE"><code class="literal">FALSE</code></a> otherwise
1097
<td> <a class="link" href="glib-Standard-Macros.html#TRUE--CAPS" title="TRUE"><code class="literal">TRUE</code></a> if the string matched, <a class="link" href="glib-Standard-Macros.html#FALSE--CAPS" title="FALSE"><code class="literal">FALSE</code></a> otherwise
1154
<em class="parameter"><code>string</code></em> is not copied and is used in <a class="link" href="glib-Perl-compatible-regular-expressions.html#GMatchInfo" title="GMatchInfo"><span class="type">GMatchInfo</span></a> internally. If
1155
you use any <a class="link" href="glib-Perl-compatible-regular-expressions.html#GMatchInfo" title="GMatchInfo"><span class="type">GMatchInfo</span></a> method (except <a class="link" href="glib-Perl-compatible-regular-expressions.html#g-match-info-free" title="g_match_info_free ()"><code class="function">g_match_info_free()</code></a>) after
1156
freeing or modifying <em class="parameter"><code>string</code></em> then the behaviour is undefined.</p>
1152
1159
<div class="variablelist"><table border="0">
1153
1160
<col align="left" valign="top">
1318
1325
stored in <em class="parameter"><code>match_info</code></em> if not <a class="link" href="glib-Standard-Macros.html#NULL--CAPS" title="NULL"><code class="literal">NULL</code></a>. Note that if <em class="parameter"><code>match_info</code></em> is
1319
1326
not <a class="link" href="glib-Standard-Macros.html#NULL--CAPS" title="NULL"><code class="literal">NULL</code></a> then it is created even if the function returns <a class="link" href="glib-Standard-Macros.html#FALSE--CAPS" title="FALSE"><code class="literal">FALSE</code></a>,
1320
1327
i.e. you must free it regardless if regular expression actually
1331
<em class="parameter"><code>string</code></em> is not copied and is used in <a class="link" href="glib-Perl-compatible-regular-expressions.html#GMatchInfo" title="GMatchInfo"><span class="type">GMatchInfo</span></a> internally. If
1332
you use any <a class="link" href="glib-Perl-compatible-regular-expressions.html#GMatchInfo" title="GMatchInfo"><span class="type">GMatchInfo</span></a> method (except <a class="link" href="glib-Perl-compatible-regular-expressions.html#g-match-info-free" title="g_match_info_free ()"><code class="function">g_match_info_free()</code></a>) after
1333
freeing or modifying <em class="parameter"><code>string</code></em> then the behaviour is undefined.</p>
1324
1336
<div class="variablelist"><table border="0">
1402
1414
stored in <em class="parameter"><code>match_info</code></em> if not <a class="link" href="glib-Standard-Macros.html#NULL--CAPS" title="NULL"><code class="literal">NULL</code></a>. Note that if <em class="parameter"><code>match_info</code></em> is
1403
1415
not <a class="link" href="glib-Standard-Macros.html#NULL--CAPS" title="NULL"><code class="literal">NULL</code></a> then it is created even if the function returns <a class="link" href="glib-Standard-Macros.html#FALSE--CAPS" title="FALSE"><code class="literal">FALSE</code></a>,
1404
1416
i.e. you must free it regardless if regular expression actually
1420
<em class="parameter"><code>string</code></em> is not copied and is used in <a class="link" href="glib-Perl-compatible-regular-expressions.html#GMatchInfo" title="GMatchInfo"><span class="type">GMatchInfo</span></a> internally. If
1421
you use any <a class="link" href="glib-Perl-compatible-regular-expressions.html#GMatchInfo" title="GMatchInfo"><span class="type">GMatchInfo</span></a> method (except <a class="link" href="glib-Perl-compatible-regular-expressions.html#g-match-info-free" title="g_match_info_free ()"><code class="function">g_match_info_free()</code></a>) after
1422
freeing or modifying <em class="parameter"><code>string</code></em> then the behaviour is undefined.</p>
1408
1425
<div class="variablelist"><table border="0">
1512
1529
<td><p><span class="term"><em class="parameter"><code>compile_options</code></em> :</span></p></td>
1513
<td> compile options for the regular expression
1530
<td> compile options for the regular expression, or 0
1517
1534
<td><p><span class="term"><em class="parameter"><code>match_options</code></em> :</span></p></td>
1535
<td> match options, or 0
1522
1539
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
1523
<td> a <a class="link" href="glib-Standard-Macros.html#NULL--CAPS" title="NULL"><code class="literal">NULL</code></a>-terminated gchar ** array. Free it using <a class="link" href="glib-String-Utility-Functions.html#g-strfreev" title="g_strfreev ()"><code class="function">g_strfreev()</code></a>
1540
<td> a <a class="link" href="glib-Standard-Macros.html#NULL--CAPS" title="NULL"><code class="literal">NULL</code></a>-terminated array of strings. Free it using <a class="link" href="glib-String-Utility-Functions.html#g-strfreev" title="g_strfreev ()"><code class="function">g_strfreev()</code></a>
1681
1698
<a class="link" href="glib-Perl-compatible-regular-expressions.html#GRegexMatchFlags" title="enum GRegexMatchFlags">GRegexMatchFlags</a> match_options,
1682
1699
<a class="link" href="glib-Error-Reporting.html#GError" title="GError">GError</a> **error);</pre>
1684
Replaces all occurances of the pattern in <em class="parameter"><code>regex</code></em> with the
1701
Replaces all occurrences of the pattern in <em class="parameter"><code>regex</code></em> with the
1685
1702
replacement text. Backreferences of the form '\number' or
1686
1703
'\g<number>' in the replacement text are interpolated by the
1687
1704
number-th captured subexpression of the match, '\g<name>' refers
1792
1809
<a class="link" href="glib-Perl-compatible-regular-expressions.html#GRegexMatchFlags" title="enum GRegexMatchFlags">GRegexMatchFlags</a> match_options,
1793
1810
<a class="link" href="glib-Error-Reporting.html#GError" title="GError">GError</a> **error);</pre>
1795
Replaces all occurances of the pattern in <em class="parameter"><code>regex</code></em> with the
1812
Replaces all occurrences of the pattern in <em class="parameter"><code>regex</code></em> with the
1796
1813
replacement text. <em class="parameter"><code>replacement</code></em> is replaced literally, to
1797
1814
include backreferences use <a class="link" href="glib-Perl-compatible-regular-expressions.html#g-regex-replace" title="g_regex_replace ()"><code class="function">g_regex_replace()</code></a>.
1863
1880
<a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer">gpointer</a> user_data,
1864
1881
<a class="link" href="glib-Error-Reporting.html#GError" title="GError">GError</a> **error);</pre>
1866
Replaces occurances of the pattern in regex with the output of
1867
<em class="parameter"><code>eval</code></em> for that occurance.
1883
Replaces occurrences of the pattern in regex with the output of
1884
<em class="parameter"><code>eval</code></em> for that occurrence.
1870
1887
Setting <em class="parameter"><code>start_position</code></em> differs from just passing over a shortened
1871
1888
string and setting <a class="link" href="glib-Perl-compatible-regular-expressions.html#G-REGEX-MATCH-NOTBOL--CAPS"><span class="type">G_REGEX_MATCH_NOTBOL</span></a> in the case of a pattern
1872
that begins with any kind of lookbehind assertion, such as "\b".</p>
1889
that begins with any kind of lookbehind assertion, such as "\b".
1892
The following example uses <a class="link" href="glib-Perl-compatible-regular-expressions.html#g-regex-replace-eval" title="g_regex_replace_eval ()"><code class="function">g_regex_replace_eval()</code></a> to replace multiple
1895
<div class="informalexample"><pre class="programlisting">
1897
eval_cb (const GMatchInfo *info,
1904
match = g_match_info_fetch (info, 0);
1905
r = g_hash_table_lookup ((GHashTable *)data, match);
1906
g_string_append (res, r);
1918
h = g_hash_table_new (g_str_hash, g_str_equal);
1920
g_hash_table_insert (h, "1", "ONE");
1921
g_hash_table_insert (h, "2", "TWO");
1922
g_hash_table_insert (h, "3", "THREE");
1923
g_hash_table_insert (h, "4", "FOUR");
1925
reg = g_regex_new ("1|2|3|4", 0, 0, NULL);
1926
res = g_regex_replace_eval (reg, text, -1, 0, 0, eval_cb, h, NULL);
1927
g_hash_table_destroy (h);
1875
1933
<div class="variablelist"><table border="0">
2334
2392
<a class="link" href="glib-Basic-Types.html#gint" title="gint">gint</a> *start_pos,
2335
2393
<a class="link" href="glib-Basic-Types.html#gint" title="gint">gint</a> *end_pos);</pre>
2337
Retrieves the position of the <em class="parameter"><code>match_num</code></em>'th capturing
2395
Retrieves the position in bytes of the <em class="parameter"><code>match_num</code></em>'th capturing
2338
2396
parentheses. 0 is the full text of the match, 1 is the first
2339
2397
paren set, 2 the second, and so on.
2436
2494
<a class="link" href="glib-Basic-Types.html#gint" title="gint">gint</a> *start_pos,
2437
2495
<a class="link" href="glib-Basic-Types.html#gint" title="gint">gint</a> *end_pos);</pre>
2439
Retrieves the position of the capturing parentheses named <em class="parameter"><code>name</code></em>.
2497
Retrieves the position in bytes of the capturing parentheses named <em class="parameter"><code>name</code></em>.
2442
2500
If <em class="parameter"><code>name</code></em> is a valid sub pattern name but it didn't match anything