1
- <!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.383 2007/07/18 03:12:42 momjian Exp $ -->
1
+ <!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.384 2007/08/11 03:56:24 tgl Exp $ -->
2
2
3
3
<chapter id="functions">
4
4
<title>Functions and Operators</title>
1499
1499
<entry><literal><function>regexp_matches</function>(<parameter>string</parameter> <type>text</type>, <parameter>pattern</parameter> <type>text</type> [, <parameter>flags</parameter> <type>text</type>])</literal></entry>
1500
1500
<entry><type>setof text[]</type></entry>
1501
1501
<entry>
1502
- Return all capture groups resulting from matching POSIX regular
1502
+ Return all captured substrings resulting from matching a POSIX regular
1503
1503
expression against the <parameter>string</parameter>. See
1504
1504
<xref linkend="functions-posix-regexp"> for more information.
1505
1505
</entry>
1511
1511
<entry><literal><function>regexp_replace</function>(<parameter>string</parameter> <type>text</type>, <parameter>pattern</parameter> <type>text</type>, <parameter>replacement</parameter> <type>text</type> [, <parameter>flags</parameter> <type>text</type>])</literal></entry>
1512
1512
<entry><type>text</type></entry>
1513
1513
<entry>
1514
- Replace substring matching POSIX regular expression. See
1514
+ Replace substring(s) matching a POSIX regular expression. See
1515
1515
<xref linkend="functions-posix-regexp"> for more information.
1516
1516
</entry>
1517
1517
<entry><literal>regexp_replace('Thomas', '.[mN]a.', 'M')</literal></entry>
1522
1522
<entry><literal><function>regexp_split_to_array</function>(<parameter>string</parameter> <type>text</type>, <parameter>pattern</parameter> <type>text</type> [, <parameter>flags</parameter> <type>text</type> ])</literal></entry>
1523
1523
<entry><type>text[]</type></entry>
1524
1524
<entry>
1525
- Split <parameter>string</parameter> using POSIX regular expression as
1525
+ Split <parameter>string</parameter> using a POSIX regular expression as
1526
1526
the delimiter. See <xref linkend="functions-posix-regexp"> for more
1527
1527
information.
1528
1528
</entry>
1534
1534
<entry><literal><function>regexp_split_to_table</function>(<parameter>string</parameter> <type>text</type>, <parameter>pattern</parameter> <type>text</type> [, <parameter>flags</parameter> <type>text</type>])</literal></entry>
1535
1535
<entry><type>setof text</type></entry>
1536
1536
<entry>
1537
- Split <parameter>string</parameter> using POSIX regular expression as
1537
+ Split <parameter>string</parameter> using a POSIX regular expression as
1538
1538
the delimiter. See <xref linkend="functions-posix-regexp"> for more
1539
1539
information.
1540
1540
</entry>
@@ -2856,11 +2856,9 @@ cast(-44 as bit(12)) <lineannotation>111111010100</lineannotation>
2856
2856
<acronym>SQL</acronym> <function>LIKE</function> operator, the
2857
2857
more recent <function>SIMILAR TO</function> operator (added in
2858
2858
SQL:1999), and <acronym>POSIX</acronym>-style regular
2859
- expressions.
2860
- Additionally, a pattern matching function,
2861
- <function>substring</function>, is available, using either
2862
- <function>SIMILAR TO</function>-style or POSIX-style regular
2863
- expressions.
2859
+ expressions. Aside from the basic <quote>does this string match
2860
+ this pattern?</> operators, functions are available to extract
2861
+ or replace matching substrings and to split a string at the matches.
2864
2862
</para>
2865
2863
2866
2864
<tip>
@@ -3186,15 +3184,20 @@ substring('foobar' from '#"o_b#"%' for '#') <lineannotation>NULL</lineannotat
3186
3184
end of the string.
3187
3185
</para>
3188
3186
3189
- <para>
3190
- Some examples:
3187
+ <para>
3188
+ Some examples:
3191
3189
<programlisting>
3192
3190
'abc' ~ 'abc' <lineannotation>true</lineannotation>
3193
3191
'abc' ~ '^a' <lineannotation>true</lineannotation>
3194
3192
'abc' ~ '(b|d)' <lineannotation>true</lineannotation>
3195
3193
'abc' ~ '^(b|c)' <lineannotation>false</lineannotation>
3196
3194
</programlisting>
3197
- </para>
3195
+ </para>
3196
+
3197
+ <para>
3198
+ The <acronym>POSIX</acronym> pattern language is described in much
3199
+ greater detail below.
3200
+ </para>
3198
3201
3199
3202
<para>
3200
3203
The <function>substring</> function with two parameters,
@@ -3246,9 +3249,7 @@ substring('foobar' from 'o(.)b') <lineannotation>o</lineannotation>
3246
3249
function's behavior. Flag <literal>i</> specifies case-insensitive
3247
3250
matching, while flag <literal>g</> specifies replacement of each matching
3248
3251
substring rather than only the first one. Other supported flags are
3249
- <literal>m</>, <literal>n</>, <literal>p</>, <literal>w</> and
3250
- <literal>x</>, whose meanings correspond to those shown in
3251
- <xref linkend="posix-embedded-options-table">.
3252
+ described in <xref linkend="posix-embedded-options-table">.
3252
3253
</para>
3253
3254
3254
3255
<para>
@@ -3264,23 +3265,25 @@ regexp_replace('foobarbaz', 'b(..)', E'X\\1Y', 'g')
3264
3265
</para>
3265
3266
3266
3267
<para>
3267
- The <function>regexp_matches</> function returns all of the capture
3268
- groups resulting from matching a POSIX regular expression pattern.
3268
+ The <function>regexp_matches</> function returns all of the captured
3269
+ substrings resulting from matching a POSIX regular expression pattern.
3269
3270
It has the syntax
3270
3271
<function>regexp_matches</function>(<replaceable>string</>, <replaceable>pattern</>
3271
3272
<optional>, <replaceable>flags</> </optional>).
3272
- If there is no match to the <replaceable>pattern</>, the function returns no rows.
3273
- If there is a match, the function returns the contents of all of the capture groups
3274
- in a text array, or if there were no capture groups in the pattern, it returns the
3275
- contents of the entire match as a single-element text array.
3273
+ If there is no match to the <replaceable>pattern</>, the function returns
3274
+ no rows. If there is a match, the function returns a text array whose
3275
+ <replaceable>n</>'th element is the substring matching the
3276
+ <replaceable>n</>'th parenthesized subexpression of the pattern
3277
+ (not counting <quote>non-capturing</> parentheses; see below for
3278
+ details). If the pattern does not contain any parenthesized
3279
+ subexpressions, then the result is a single-element text array containing
3280
+ the substring matching the whole pattern.
3276
3281
The <replaceable>flags</> parameter is an optional text
3277
3282
string containing zero or more single-letter flags that change the
3278
- function's behavior. Flag <literal>i</> specifies case-insensitive
3279
- matching, while flag <literal>g</> causes the return of each matching
3280
- substring rather than only the first one. Other supported
3281
- flags are <literal>m</>, <literal>n</>, <literal>p</>, <literal>w</> and
3282
- <literal>x</>, whose meanings are described in
3283
- <xref linkend="posix-embedded-options-table">.
3283
+ function's behavior. Flag <literal>g</> causes the function to find
3284
+ each match in the string, not only the first one, and return a row for
3285
+ each such match. Other supported
3286
+ flags are described in <xref linkend="posix-embedded-options-table">.
3284
3287
</para>
3285
3288
3286
3289
<para>
@@ -3319,16 +3322,14 @@ SELECT regexp_matches('foobarbequebaz', 'barbeque');
3319
3322
returns the text from the end of the last match to the end of the string.
3320
3323
The <replaceable>flags</> parameter is an optional text string containing
3321
3324
zero or more single-letter flags that change the function's behavior.
3322
- <function>regexp_split_to_table</function> supports the flags <literal>i</>,
3323
- <literal>m</>, <literal>n</>, <literal>p</>, <literal>w</> and
3324
- <literal>x</>, whose meanings are described in
3325
+ <function>regexp_split_to_table</function> supports the flags described in
3325
3326
<xref linkend="posix-embedded-options-table">.
3326
3327
</para>
3327
3328
3328
3329
<para>
3329
3330
The <function>regexp_split_to_array</> function behaves the same as
3330
3331
<function>regexp_split_to_table</>, except that <function>regexp_split_to_array</>
3331
- returns its results as a <type>text[] </>. It has the syntax
3332
+ returns its result as an array of <type>text</>. It has the syntax
3332
3333
<function>regexp_split_to_array</function>(<replaceable>string</>, <replaceable>pattern</>
3333
3334
<optional>, <replaceable>flags</> </optional>).
3334
3335
The parameters are the same as for <function>regexp_split_to_table</>.
0 commit comments