Regular Expressions and Pattern Matching

In addition to the information below, here is a good external site on understanding Regular Expressions.

The capabilities for finding patterns in strings is very powerful using a concept called "Regular Expressions", which is often abbreviated REGEX or REGEXP.  Regular expressions allow for very flexible and complex patterns to be described and found in strings, and the related LityxIQ functions allow you to find, replace, count, and perform other operations on matched patterns.  Regular expressions are very hard to learn, but can be very powerful.  We recommend online resources such as https://regex101.com as a great resource with documentation and ability to easily test Regex's.

Once you have a regular expression figured out that does what you need to do, you can use it in LityxIQ in a number of functions.  There include REGEXP_COUNT, REGEXP_INSTR, REGEXP_REPLACE, REGEXP_SUBSTR.  It also includes to ~ operator.  All of these are documented here: https://support.lityxiq.com/622506-Pattern-Matching--REGEX-Functions.

Here are a few examples of pattern matching objectives, inputs, code, and expected outputs.

Objective

Sample Strings in variable

named str

Code

Result

Find strings that start with the letter C (capitalized) followed by at least one digit.

C62d

D4

Cxy

h23

xC3

Case when [str] ~ ‘^C[[:digit:]]+’ then 1 else 0 end

1

0

0

0

0

Find strings with three capital letters in a row starting with K, immediately followed by three digits.  No other characters allowed, 6 total.

KRR389

Krp203

K20CG3

KRR3892

UIQ203

Case when [str] ~ ‘^K[A-Z]{2}[[:digit:]]{3}$’ then 1 else 0 end

1

0

0

0

0