This function searches the text character string for a part described by the regular expression pattern.
This function is built on the PCRE (Perl-Compatible Regular Expression) library corresponding with the PERL program version 5.8.
THe regular expression must be specified according to the PERL language rules:
The ^ and $ character on the beginning and end of a regular expression allow to "anchor" it, so the regular expression doesn't have to cover the whole extent of the text from the beginning to end. Hence the function may search for a substring, prefix, suffix or the equality of the whole text with the regular expression.
If the text of the regular expression are not in Unicode, it is assumed, that the regular expression can be converted into the text charset.
If the options parameter is specified, it contains characters that alter the regular expression behaviour:
Searching with the regular expression is fast, because the text is always searched in linear time no matter how complex the expression is. Searching with the regular expression condition doesn't use indexes and therefore leads to searching one text after another. This is not very effective method for vast database texts, a good alternative is the use of fulltext tools.
The REGEXP_LIKE function is more flexible and effective than the LIKE function.
Returns the result of comparing the text with the regular expression - TRUE if they're corresponding, FALSE otherwise. The function returns UNKNOWN if the regular expression syntax is incorrect.
SELECT * FROM Txtab WHERE Regexp_like(name, 'A(be|braham|\.) +Lincoln', 'i')
This query selects thos records from the Txtab table, that have the 'Abe Lincoln', 'Abraham Lincoln' or 'A. Lincoln' in the Name column (there may be more spaces between both words). This query is not case-sensitive.
SELECT company FROM Addresses WHERE REGEXP_LIKE(company,'[0-9]+'); //WHERE REGEXP_LIKE(company,'[0-9]{1,}'); //WHERE REGEXP_LIKE(company,'[[:digit:]]+'); //WHERE REGEXP_LIKE(company,'\d+');
This query selects those companies, that have at least on digit in their name. Valid names: 'Software602 a.s.', 'TELE3', 'VÜ 1444', 'O2'. 4 equivalent notations of the regular expression are used in the example.