Home Explore Blog CI



postgresql

74th chunk of `doc/src/sgml/func.sgml`
cae1b2e8f1104ce534519c8ac515720ca6c34ff4e7e37a2b0000000100000fa7
 <replaceable>N</replaceable>'th match of the pattern
     is located, otherwise the first match is located.
     If the <replaceable>endoption</replaceable> parameter is omitted or
     specified as zero, the function returns the position of the first
     character of the match.  Otherwise, <replaceable>endoption</replaceable>
     must be one, and the function returns the position of the character
     following the match.
     The <replaceable>flags</replaceable> parameter is an optional text
     string containing zero or more single-letter flags that change the
     function's behavior.  Supported flags are described
     in <xref linkend="posix-embedded-options-table"/>.
     For a pattern containing parenthesized
     subexpressions, <replaceable>subexpr</replaceable> is an integer
     indicating which subexpression is of interest: the result identifies
     the position of the substring matching that subexpression.
     Subexpressions are numbered in the order of their leading parentheses.
     When <replaceable>subexpr</replaceable> is omitted or zero, the result
     identifies the position of the whole match regardless of
     parenthesized subexpressions.
    </para>

    <para>
     Some examples:
<programlisting>
regexp_instr('number of your street, town zip, FR', '[^,]+', 1, 2)
                                   <lineannotation>23</lineannotation>
regexp_instr(string=>'ABCDEFGHI', pattern=>'(c..)(...)', start=>1, "N"=>1, endoption=>0, flags=>'i', subexpr=>2)
                                   <lineannotation>6</lineannotation>
</programlisting>
    </para>

    <para>
     The <function>regexp_like</function> function checks whether a match
     of a POSIX regular expression pattern occurs within a string,
     returning boolean true or false.  It has the syntax
     <function>regexp_like</function>(<replaceable>string</replaceable>,
     <replaceable>pattern</replaceable>
     <optional>, <replaceable>flags</replaceable> </optional>).
     The <replaceable>flags</replaceable> parameter is an optional text
     string containing zero or more single-letter flags that change the
     function's behavior.  Supported flags are described
     in <xref linkend="posix-embedded-options-table"/>.
     This function has the same results as the <literal>~</literal>
     operator if no flags are specified.  If only the <literal>i</literal>
     flag is specified, it has the same results as
     the <literal>~*</literal> operator.
    </para>

    <para>
     Some examples:
<programlisting>
regexp_like('Hello World', 'world')       <lineannotation>false</lineannotation>
regexp_like('Hello World', 'world', 'i')  <lineannotation>true</lineannotation>
</programlisting>
    </para>

    <para>
     The <function>regexp_match</function> function returns a text array of
     matching substring(s) within the first match of a POSIX
     regular expression pattern to a string.  It has the syntax
     <function>regexp_match</function>(<replaceable>string</replaceable>,
     <replaceable>pattern</replaceable> <optional>, <replaceable>flags</replaceable> </optional>).
     If there is no match, the result is <literal>NULL</literal>.
     If a match is found, and the <replaceable>pattern</replaceable> contains no
     parenthesized subexpressions, then the result is a single-element text
     array containing the substring matching the whole pattern.
     If a match is found, and the <replaceable>pattern</replaceable> contains
     parenthesized subexpressions, then the result is a text array
     whose <replaceable>n</replaceable>'th element is the substring matching
     the <replaceable>n</replaceable>'th parenthesized subexpression of
     the <replaceable>pattern</replaceable> (not counting <quote>non-capturing</quote>
     parentheses; see below for details).
     The <replaceable>flags</replaceable> parameter is an optional text string
     containing zero or more single-letter flags that change the function's
     behavior.  Supported

Title: regexp_instr, regexp_like, and regexp_match Functions
Summary
This section explains the `regexp_instr`, `regexp_like`, and `regexp_match` functions. `regexp_instr` details how to specify which match to locate, whether to return the start or end position, flags for modifying behavior, and the subexpression to focus on. `regexp_like` checks if a POSIX regular expression pattern matches within a string, returning a boolean, and mentions the equivalence to the `~` and `~*` operators with and without the 'i' flag. Finally, `regexp_match` returns a text array of matching substrings for the first match of a POSIX regular expression. The content of the array depends on whether the pattern includes parenthesized subexpressions.