Overview
TheREGEXP_MATCH()
function matches a POSIX regular expression pattern to a string. It returns an array of TEXT[]
type with substring(s) of matched groups within the first match.
Syntax
The syntax forREGEXP_MATCH()
function is as follows:
Parameters
source_string
: string on which you want to perform the matchingpattern
: POSIX regular expression pattern to matchflags
: (optional) string with flags that change the matching behavior ofREGEXP_MATCH()
function
flags
parameter is an optional string that controls how the function operates. Here is a list of flags that are supported by Oxla:
i
: use this flag for case-insensitive matchingc
:REGEXP_MATCH()
function is case sensitive by default, using thec
flag has the same effect as having no flags at all
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-sensitiveExamples
Basic ssage
The following example demonstrates how to find the first occurrence of an email address in the input string:Matching multiple groups
TheREGEXP_MATCH()
function can capture multiple groups within a match, which allow you to extract key parts from a string in a structured way. The example below extracts the protocol, domain and path from a given URL:
Case-insensitive matching
This example shows how to match a pattern regardless of case-sensitivity:Matching with patterns stored in a table
In this example we will show you how to take the source string and regex pattern directly from the table. For the needs of this section, let’s create two sample tables:users
table are valid. If the regex doesn’t match, a NULL
value is returned.
Restrictions
- The function returns
NULL
if it cannot match the regular expression pattern i
andc
flags shouldn’t be used with each other