Home Explore Blog CI



postgresql

42th chunk of `doc/src/sgml/func.sgml`
a3cd60b9aa71ba02e7bb44bfae01dbb65fd0001d2e68c9e80000000100000fa1
 <function>regexp_substr</function> ( <parameter>string</parameter> <type>text</type>, <parameter>pattern</parameter> <type>text</type>
         <optional>, <parameter>start</parameter> <type>integer</type>
         <optional>, <parameter>N</parameter> <type>integer</type>
         <optional>, <parameter>flags</parameter> <type>text</type>
         <optional>, <parameter>subexpr</parameter> <type>integer</type> </optional> </optional> </optional> </optional> )
        <returnvalue>text</returnvalue>
       </para>
       <para>
        Returns the substring within <parameter>string</parameter> that
        matches the <parameter>N</parameter>'th occurrence of the POSIX
        regular expression <parameter>pattern</parameter>,
        or <literal>NULL</literal> if there is no such match; see
        <xref linkend="functions-posix-regexp"/>.
       </para>
       <para>
        <literal>regexp_substr('ABCDEF', 'c(.)(..)', 1, 1, 'i')</literal>
        <returnvalue>CDEF</returnvalue>
       </para>
       <para>
        <literal>regexp_substr('ABCDEF', 'c(.)(..)', 1, 1, 'i', 2)</literal>
        <returnvalue>EF</returnvalue>
       </para></entry>
      </row>

      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <indexterm>
         <primary>repeat</primary>
        </indexterm>
        <function>repeat</function> ( <parameter>string</parameter> <type>text</type>, <parameter>number</parameter> <type>integer</type> )
        <returnvalue>text</returnvalue>
       </para>
       <para>
        Repeats <parameter>string</parameter> the specified
        <parameter>number</parameter> of times.
       </para>
       <para>
        <literal>repeat('Pg', 4)</literal>
        <returnvalue>PgPgPgPg</returnvalue>
       </para></entry>
      </row>

      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <indexterm>
         <primary>replace</primary>
        </indexterm>
        <function>replace</function> ( <parameter>string</parameter> <type>text</type>,
        <parameter>from</parameter> <type>text</type>,
        <parameter>to</parameter> <type>text</type> )
        <returnvalue>text</returnvalue>
       </para>
       <para>
        Replaces all occurrences in <parameter>string</parameter> of
        substring <parameter>from</parameter> with
        substring <parameter>to</parameter>.
       </para>
       <para>
        <literal>replace('abcdefabcdef', 'cd', 'XX')</literal>
        <returnvalue>abXXefabXXef</returnvalue>
       </para></entry>
      </row>

      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <indexterm>
         <primary>reverse</primary>
        </indexterm>
        <function>reverse</function> ( <type>text</type> )
        <returnvalue>text</returnvalue>
       </para>
       <para>
        Reverses the order of the characters in the string.
       </para>
       <para>
        <literal>reverse('abcde')</literal>
        <returnvalue>edcba</returnvalue>
       </para></entry>
      </row>

      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <indexterm>
         <primary>right</primary>
        </indexterm>
        <function>right</function> ( <parameter>string</parameter> <type>text</type>,
         <parameter>n</parameter> <type>integer</type> )
        <returnvalue>text</returnvalue>
       </para>
       <para>
        Returns last <parameter>n</parameter> characters in the string,
        or when <parameter>n</parameter> is negative, returns all but
        first |<parameter>n</parameter>| characters.
       </para>
       <para>
        <literal>right('abcde', 2)</literal>
        <returnvalue>de</returnvalue>
       </para></entry>
      </row>

      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <indexterm>
         <primary>split_part</primary>
        </indexterm>
        <function>split_part</function> ( <parameter>string</parameter>

Title: PostgreSQL String Functions: REGEXP_SUBSTR (cont.), REPEAT, REPLACE, REVERSE, RIGHT
Summary
This section describes several PostgreSQL string functions. It continues the description of `regexp_substr` showing how to extract the substring that matches the Nth capturing subexpression within the regular expression. It also includes `repeat` to repeat a string a specified number of times, `replace` to replace all occurrences of a substring, `reverse` to reverse the characters in a string, and `right` to extract the last N characters of a string.