IsRegexMatch

The IsRegexMatch function uses Java regular expressions to search a string. The function returns ‘true’ if a match is found, otherwise it returns ‘false’.

Syntax

IsRegexMatch(<string>, <regex>)

Return Type

Boolean

Details

Connect uses Java’s regular expression syntax. While not documented here, the Web has many resources to learn Java’s syntax. Refer to the examples below for a small sample of use cases.

Examples

The first two examples show differences in searching for “like” matches using the + and * regex syntax.

select 'fox runs fast' as fox,
IsRegexMatch('fox runs fast', 'fo.+') as fox_starts_with_fo,
'A dog wags its tail 100 times.' as dog,
IsRegexMatch('A dog wags its tail 100 times.', 'fo.+') as dog_starts_with_fo,
'Don''t forget the cats' as cats,
IsRegexMatch('Don''t forget the cats', 'fo.+') as cats_starts_with_fo
from Empty();

isregexmatch_01

select 'fox runs fast' as fox,
IsRegexMatch('fox runs fast', '.+fo.+') as "fox_like_+fo*",
IsRegexMatch('fox runs fast', '.*fo.+') as "fox_like_*fo*",
'Don''t forget the cats' as cats ,
IsRegexMatch('Don''t forget the cats', '.+fo.+') as "cats_like_+fo*",
IsRegexMatch('Don''t forget the cats', '.*fo.+') as "cats_like_*fo*"
from Empty();

isregexmatch_02

The final example shows different ways to search for numeric values.

select 'fox runs fast' as fox,
IsRegexMatch('fox runs fast', '.+[0-9].+') as fox_contains_a_number,
'A dog wags its tail 100 times.' as dog,
IsRegexMatch('A dog wags its tail 100 times.', '.+[0-9].+') as dog_contains_a_number,
IsRegexMatch('A dog wags its tail 100 times.', '.+[0-9][0-9][0-9].+') as dog_contains_three_numbers,
IsRegexMatch('A dog wags its tail 100 times.', '.+[0-9][0-9][0-9][0-9].+') as dog_contains_four_numbers
from Empty();

isregexmatch_03

Related Functions

ReplaceAll