Regular expressions are a powerful tool for finding strings, checking them against some pattern, and other similar work.
Features of creating regular expressions:
the case of characters in the string is taken into account;
special characters ** must be escaped. ^ $ * + ? { } [ ] \ | ( )** preceded by a backslash \;
When creating a Dictionary Search policy, you can use the Regular Expression Builder to create and test your own regular expression.
Note
Please note that the word boundary special character \b is processed differently in PostgreSQL and ClickHouse:
in PostgreSQL \b is replaced by \y, which fires at the beginning and end of a word;
in PostgreSQL \b also works after a special character and with Unicode;
ClickHouse does not support Unicode; the beginning of a word is counted only after a space, tab, or the beginning of a line.
More special characters for regular expressions are presented on the website for creating expressions https://regex101.com/
Regular expression examples
Search in the text of an e-mail or AD login
(\s|^|\n|\b)(\w|\.?|\-?)+@([A-zА-я0-9][-A-zА-я0-9]+\.)+[A-zА-я]{2,13}((\s|$|\n|\b))
Car license plates, extended and short
(А|В|Е|К|М|Н|О|Р|С|Т|У|Х)(\s|\-)?\d{3}(А|В|Е|К|М|Н|О|Р|С|Т|У|Х){2}(\s|\-)?\d{2,3}
(A|B|E|K|M|H|O|P|C|T|Y|X)(\s|\-)?\d{3}(A|B|E|K|M|H|O|P|C|T|Y|X){2}(\s|\-)?\d{2,3}
(A|B|E|K|M|H|O|P|C|T|Y|X){3}(\s|\-)?\d{3}(\s|\-)?\d{2,3} (\s|\n|\b|^\d)
OSAGO policy
(^|.*)(РРР|ННН|ХХХ|ТТТ|ААС|ААВ|ААК|ААМ)(-|\s)\d{10}\s
IP address
([0-9]{1,3}[\.]){3}[0-9]{1,3}
Find word in any case
слово
Mobile phone number
(8|\+7)?(\-|\s)?((9\d{9})|(\(?9\d{2}\)?)(((\-|\s)\d{2,4}){2,3}|(\s|-)\d{7}))
Landline phone number in the format 8-(area code)-phone_number (8-(123)-456-78-90)
(8|\+7)?(\-|\s)?((383\d{7})|(\(?383\)?)(((\-|\s)\d{2,4}){2,3}|(\s|-)\d{7})) – код 383
(8|\+7)?(\-|\s)?((495\d{7})|(\(?495\)?)(((\-|\s)\d{2,4}){2,3}|(\s|-)\d{7})) – код 495
(8|\+7)?(\-|\s)?((499\d{7})|(\(?499\)?)(((\-|\s)\d{2,4}){2,3}|(\s|-)\d{7})) – код 499
(8|\+7)?(\-|\s)?((812\d{7})|(\(?812\)?)(((\-|\s)\d{2,4}){2,3}|(\s|-)\d{7})) – код 812