9.11 REGEXP Function

This function escapes characters that can change the context in a regular expression. It should be used to secure user input. The following list depicts ascii characters that the function escapes with a backslash (\):

\.^$*+-?()[]{|

Syntax

APEX_ESCAPE.REGEXP (
    p_string IN VARCHAR2);

Parameters

Table 9-12 APEX_ESCAPE.REGEXP Function Parameters

Parameter Description

p_string

Text to escape.

Example

The following example ensures the special character "-" in Mary-Ann will be escaped and ignored by the regular expression engine.

declare
    l_subscribers varchar2(4000) := 'Christina,Hilary,Mary-Ann,Joel';
    l_name varchar2(4000) := 'Mary-Ann';
begin
    if regexp_instr(l_subscribers,'(^|,)'|| apex_escape.regexp(l_name)||'($|,)')>0
    then
        sys.htp.p('found');
    else
        sys.htp.p('not found')
    endif;
end