Oracle REGEXP Guide: Like & Replace Examples
The REGEXP regular expression function in Oracle can be used in the following way:
- REGEXP_LIKE: Used to check if a string matches a regular expression. Syntax is as follows: REGEXP_LIKE(source_string, pattern, match_parameter)
- Choose ‘Hello World’ from dual where ‘Hello World’ contains ‘Hello.*’
- REGEXP_REPLACE is used to replace the strings matched by a regular expression with a specified string. The syntax is as follows:
REGEXP_REPLACE(source_string, pattern, replace_string) - Replace the word ‘World’ with ‘Universe’ in the phrase ‘Hello World’.
- REGEXP_INSTR is used to return the position of a regular expression within a string. Its syntax is as follows: REGEXP_INSTR(source_string, pattern, position, occurrence, match_parameter)
- For instance:
SELECT REGEXP_INSTR(‘Hello World’, ‘World’) FROM dual
- REGEXP_SUBSTR is used to return the substring that matches the regular expression. The syntax is as follows:
REGEXP_SUBSTR(source_string, pattern, position, occurrence, match_parameter) - Choose REGEXP_SUBSTR(‘Hello World’, ‘Hello.*’) FROM dual
It is important to note that Oracle’s regular expression syntax is slightly different from standard regular expression syntax, you can refer to the official Oracle documentation for specific syntax.