Name
regexp_parse — returns substrings that match the regular expression in supplied string after an offset
Synopsis
index_vector
regexp_parse
(
|
in pattern string , |
in target_string string , | |
in
offset
integer
) ; |
Description
It applies regular expression to target_str with offset. This function returns a vector containing 2 elements for first match of the pattern and if there a sub expressions : 2 elements for each of subexpression match. The first (even numbered) element of each pair is the start index and the second (odd numbered) is the end index of the match. The regexp_parse function is more efficient than regexp_match and regexp_substr, because it doesn't allocate strings.
SQL> select regexp_parse('(2[34]).*(2[35])','22232225222323', 0); callret VARCHAR _______________________________________________________________________________ lvector(2,14,2,4,12,14) 1 Rows. -- 10 msec.
Where: 2-14 is a range matched by whole expression, 2-4 is a range where '(2[34])' is matched , and 12-14 is a range where '(2[35])' subexpression matched.
Example 24.252. Examples
CREATE PROCEDURE all_tokens2 (IN pattern VARCHAR,IN str VARCHAR, IN offs INTEGER) { DECLARE vec ANY; DECLARE i INTEGER; DECLARE out_str VARCHAR; vec:=regexp_parse(pattern,str,offs); IF ((vec IS NOT NULL) AND (length(vec)>1)) { out_str:=''; i:=0; WHILE ( (length(vec)/2) > i ) { out_str:=concat(out_str,'/', subseq(str,aref(vec,(i)*2), aref(vec,(i)*2+1))); i:=i+1; }; RETURN concat(out_str,test_parsing(pattern,str,aref(vec,1)+1)); } return NULL; };