REGEXP_REPLACE()
function replaces all occurrences of a regular expression pattern in a string with a specified replacement string.
REGEXP_REPLACE()
function is as follows:
source_string
: string that we want to perform the replacement onpattern
: POSIX regular expression pattern to matchreplacement
: replacement stringflags
: (optional) string that changes the matching behavior of REGEXP_REPLACE()
functionflags
parameter is an optional string that controls how the function operates. Here is a list of flags supported in Oxla:
g
: global replacement. This flag ensures that all occurrences of the pattern are replacedi
: use this flag for case-insensitive matchingc
: REGEXP_REPLACE()
function is case sensitive by default, using the c
flag has the same effect as using no flagsREGEXP_REPLACE()
function with a basic POSIX regular expression pattern:
REGEXP_REPLACE()
function with a defined flag and replacing certain substrings in a string. For the needs of this section, we will create a sample quotes
table:
REGEXP_REPLACE()
function with the i
flag specifiec to replace all occurrences of the word lazy
with active
regardless of the case sensitivity:
lazy
have been replaced with active
:
g
flag, REGEXP_REPLACE()
function replaces only the first occurrence of a substring:
1
) was replaced with X
. By adding the g
flag, all occurrences are replaced with X
:
ci
flags, the regex will be case-insensitive, while using the ic
flags it will be case-sensitiveNULL
if there are no input rows or NULL
valuesREGEXP_REPLACE()
function returns the original stringi
and c
flags shouldn’t be used with each other