REGEXP_INSTR
Syntax
REGEXP_INSTR(expr, pat [, pos [, occurrence [, return_option [, match_type ]]]])
Description
REGEXP_INSTR returns the starting position of the substring in expr that matches the pattern pat. If no substring matches the pattern, it returns 0. If expr or pat is NULL, it returns NULL. Positions count UTF-16 code units starting from 1.
-
posis the 1-based UTF-16 position at which the search starts. The default is1. A position inside a surrogate pair is invalid. -
occurrencespecifies the occurrence of the pattern inexpr. The default value is1. -
return_optionspecifies the type of the return value. The default value is0.-
When
return_optionis0,REGEXP_INSTR()returns the position of the first character that matches the pattern. -
When
return_optionis1,REGEXP_INSTR()returns the position immediately after the match.
-
-
match_typespecifies the matching rule. For more information about the matching rules, see REGEXP_LIKE.
Examples
SELECT REGEXP_INSTR('ocean base oceanbase', 'ocean');
+-----------------------------------------------+
| REGEXP_INSTR('ocean base oceanbase', 'ocean') |
+-----------------------------------------------+
| 1 |
+-----------------------------------------------+
1 row in set (0.001 sec)
SELECT REGEXP_INSTR('ocean base oceanbase', 'ocean',2);
+-------------------------------------------------+
| REGEXP_INSTR('ocean base oceanbase', 'ocean',2) |
+-------------------------------------------------+
| 12 |
+-------------------------------------------------+
1 row in set (0.001 sec)
SELECT REGEXP_INSTR('ocean base oceanbase', 'ocean',1,2);
+---------------------------------------------------+
| REGEXP_INSTR('ocean base oceanbase', 'ocean',1,2) |
+---------------------------------------------------+
| 12 |
+---------------------------------------------------+
1 row in set (0.001 sec)
SELECT REGEXP_INSTR('ocean base oceanbase', 'ocean',1,2,1);
+-----------------------------------------------------+
| REGEXP_INSTR('ocean base oceanbase', 'ocean',1,2,1) |
+-----------------------------------------------------+
| 17 |
+-----------------------------------------------------+
1 row in set (0.001 sec)