The Regexp_like is a new function introduced in MySQL 8. It compares a string with a regex pattern and returns whether they match or not. The Regexp_like command gives back a 1 if there is a match or 0 if there is no match.
The Basic Syntax of regexp_like() is,
REGEXP_LIKE (expression, pattern [, match_type])
Where,
expression: It is an input string on which we perform searching for matching the regular expression.
pattern: It represents the regular expression for which we are testing the string.
match_type: It is a string that allows us to refine the regular expression. It uses the following possible characters to perform matching.
Below are a few examples of the regexp_like functions. In the examples below we use the regexp_like function in the select statement. However we can use theregexp_like in the where clause as well.
select regexp_like('new*\n*line', '.*');
This checks if the string has the pattern TE one or more times in the string.
SELECT regexp_like('ARACHNOPHOBIA ROLLERCOASTER','TE+');
select regexp_like('Questionnaire,Bonanza,Network','[y]'),regexp_like('Questionnaire,Bonanza,Network','[^y]');