Name
regexp_match — returns a substring matching the regular expression to the supplied string
Synopsis
varchar
regexp_match
(
|
in pattern any , |
inout str any , | |
in
change_the_str
integer
) ; |
Description
The regexp_match function returns a copy of substring of string
str
which matches the regular expression pattern.
Previous behavior of this function would cut the first characters of str
until the end of regular expression matched substring. In this way
str
could be passed to this function again to find
the next occurrence of substring that matches the regular expression. By
default this behavior is not adopted by this function, but can be enabled for
pre 3.2 compatibility by supplying the optional third parameter.
If either the pattern
or str
parameter contain wide characters this function will operate in wide mode,
first converting any narrow characters to wide and returning a wide character
response. Otherwise this function operates in narrow mode by default.
Parameters
pattern
The regular expression to match.
str
The string to be searched. In compatibility mode (change_the_str =1) this string in modified, removing the matched substring.
change_the_str
This new parameter allows this function to operate in pre 3.2 compatibility mode which modified the original string. By default this parameter is set to "0" so that the original string is never altered.
Returns
This function returns the a substring matching the regular expression.
Examples
Example 24.251. Examples
CREATE PROCEDURE all_tokens(IN pattern VARCHAR, IN str VARCHAR) { DECLARE wrd VARCHAR; DECLARE ans VARCHAR; DECLARE str_i VARCHAR; ans:=''; str_i := str; wrd := regexp_match(pattern,str_i); WHILE (wrd IS NOT NULL) { ans := concat(ans,',',wrd); wrd := regexp_match(pattern, str_i, 1); }; RETURN ans; };