Documentation Index
Fetch the complete documentation index at: https://docs.oxla.com/llms.txt
Use this file to discover all available pages before exploring further.
Overview
TheREGEXP_REPLACE() function replaces all occurrences of a regular expression pattern in a string with a specified replacement string.
Syntax
The syntax forREGEXP_REPLACE() function is as follows:
Parameters
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 ofREGEXP_REPLACE()function
flags 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 thecflag has the same effect as using no flags
Examples
Basic function usage
In this example, we will focus on usingREGEXP_REPLACE() function with a basic POSIX regular expression pattern:
Replacing special characters
This example demonstrates how to replace a non-alphanumeric character in a string with a tilde (~):Flags usage
Replacing certain substrings with a single flag defined
This example will focus on using theREGEXP_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:
Specifying one or more flags
Without specifying theg 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:
If you use multiple flags, the last one takes precedence. If you use the
ci flags, the regex will be case-insensitive, while using the ic flags it will be case-sensitiveRestrictions
- The function returns
NULLif there are no input rows orNULLvalues - If the regular expression pattern isn’t found in the string, the
REGEXP_REPLACE()function returns the original string iandcflags shouldn’t be used with each other