1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
-
- This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
- project.
-
- Copyright (C) 1998-2018 OpenLink Software
-
- This project is free software; you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published by the
- Free Software Foundation; only version 2 of the License, dated June 1991.
-
- This program is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
-
-->
<refentry id="fn_regexp_substr">
<refmeta>
<refentrytitle>regexp_substr</refentrytitle>
<refmiscinfo>string</refmiscinfo>
</refmeta>
<refnamediv>
<refname>regexp_substr</refname>
<refpurpose>returns a single captured substring from matched substring</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis id="fsyn_regexp_substr">
<funcprototype id="fproto_regexp_substr">
<funcdef>(varchar|nvarchar) <function>regexp_substr</function></funcdef>
<paramdef>in <parameter>pattern</parameter> (varchar|nvarchar)</paramdef>
<paramdef>in <parameter>str</parameter> (varchar|nvarchar)</paramdef>
<paramdef>in <parameter>offset</parameter> integer</paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1 id="params_regexp_substr"><title>Parameters</title>
<refsect2><title>pattern</title>
<para>the regexp pattern string</para>
</refsect2>
<refsect2><title>str</title>
<para>the data into which 1 (the first) or 0 matching substrings will be searched for</para>
</refsect2>
<refsect2><title>offset</title>
<para>the number of regexp subexpression who's match to return : 0 for the whole matching substring,
1 for the substring matching the first regexp subexpression and so on</para>
</refsect2>
</refsect1>
<refsect1 id="desc"><title>Description</title>
<para>This function will return the whole string value of the first substring in "str"
that matches the regexp in "pattern" or a sub part of the first match.
The regexp syntax allows subexpressions to be marked in the regular expression
(using the braces syntax). An example of such type of expression will be: '(2[34]).*(2[35])' which means a regular
expression having two subexpressions: '2[34]' and '2[35]'.</para>
</refsect1>
<refsect1 id="examples_regexp_substr"><title>Examples</title>
<example id="ex_regexp_substr_1"><title>Simple example</title>
<para>Let's apply the above regexp to the following source string: 22232225222323</para>
<screen>
SQL> select regexp_substr('(2[34]).*(2[35])','22242226222527', 0);
callret
VARCHAR
_______________________________________________________________________________
2422262225
1 Rows. -- 0 msec.
</screen>
<para>This returns the whole matched string from the expression.</para>
<screen>
SQL> select regexp_substr('(2[34]).*(2[35])','22242226222527', 1);
callret
VARCHAR
_______________________________________________________________________________
24
1 Rows. -- 0 msec.
</screen>
<para>This returns what has been matched for the first ('2[34]') regexp subexpression
out of the whole matched substring (see above) : basically denoted as \1 in perl</para>
<screen>
SQL> select regexp_substr('(2[34]).*(2[35])','22242226222527', 2);
callret
VARCHAR
_______________________________________________________________________________
25
1 Rows. -- 10 msec.
</screen>
<para>This returns what has been matched for the second ('2[35]') regexp subexpression
out of the whole matched substring. This is \2 in perl.
Note that the text '22' (that corresponds to '.*' part of the regexp) is not
returned by the above call because it is not contained in the second pair of braces.</para>
</example>
</refsect1>
<refsect1 id="seealso_regexp_substr"><title>See Also</title>
<para><link linkend="fn_regexp_match"><function>regexp_match()</function></link></para>
<para><link linkend="fn_regexp_like"><function>regexp_like()</function></link></para>
<para><link linkend="fn_regexp_parse"><function>regexp_parse()</function></link></para>
<para><link linkend="fn_regexp_replace"><function>regexp_replace()</function></link></para>
<para><link linkend="fn_regexp_instr"><function>regexp_instr()</function></link></para>
</refsect1>
</refentry>
|