Text

First match of a text against a regular expression using First Text Match block

First match of a text against a regular expression in Centrldesk

The First Text Match block is used to get the result of the first match of a text against a regular expression.

A regular expression or regex is a sequence of characters that specifies a search pattern in text. If the text matches the regex to be checked, it returns the first result.

Example A:

library-text-functions-firstmatch-example-1-1

Using the input Expression 'gr[ae]y' for input Text 'red grey blue gray' the text 'grey' is returned.

Example B:

library-text-functions-firstmatch-example-2-1

Using the input Expression 'gr[ae]y' for input Text 'red green blue gray' the text 'gray' is returned.

Result:

Text that first matches the regular expression.

Tips and best practices:

List of regular expression examples:

Regex Matches any string that
hello contains {hello}
gray|grey contains {gray, grey}
gr(a|e)y contains {gray, grey}
gr[ae]y contains {gray, grey}
b[aeiou]bble contains {babble, bebble, bibble, bobble, bubble}
[b-chm-pP]at|ot contains {bat, cat, hat, mat, nat, oat, pat, Pat, ot}
colou?r contains {color, colour}
rege(x(es)?|xps?) contains {regex, regexes, regexp, regexps}
go*gle contains {ggle, gogle, google, gooogle, goooogle, ...}
go+gle contains {gogle, google, gooogle, goooogle, ...}
g(oog)+le contains {google, googoogle, googoogoogle, googoogoogoogle, ...}
z{3} contains {zzz}
z{3,6} contains {zzz, zzzz, zzzzz, zzzzzz}
z{3,} contains {zzz, zzzz, zzzzz, zzzzzz}
z{3,} contains {zzz, zzzz, zzzzz, ...}
\d contains {0,1,2,3,4,5,6,7,8,9}
\d{5}(-\d{4})? contains a United States zip code
1\d{10} contains an 11-digit string starting with a 1
[2-9]|[12]\d|3[0-6] contains an integer in the range 2..36 inclusive
^cat begins with "cat"
cat$ ends with "cat"
^cat$ is exactly "cat"

Library:

Text

Similar posts

Subscribe to our newsletter

Stay up to date on upcoming news and topics of creating web apps without code.