C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
MySQL REGEXP_LIKE() FunctionThe REGEXP_LIKE() function in MySQL is used for pattern matching. It compares whether the given strings match a regular expression or not. It returns 1 if the strings match the regular expression and return 0 if no match is found. SyntaxThe following is a basic syntax to use this function in MySQL: REGEXP_LIKE (expression, pattern [, match_type]) Parameter ExplanationThe explanation of the REGEXP_LIKE() function parameters are: 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.
Let us understand how we can use this function in MySQL with various examples. ExampleThe following statement explains the basic example of the REGEXP_LIKE function in MySQL. mysql> SELECT REGEXP_LIKE ('England or America', 'l.nd') AS Result; In this example, the regular expression can specify any character in place of the dot. Therefore, we will get a match here. So this function returns 1 to indicate a match. The below statement is another example where the input string does not match the given regular expression. mysql> SELECT REGEXP_LIKE ('MCA', 'BCA') AS Result; Here is the output: The below statement is another example where the specified regular expression searches whether the string end with the given characters or not: mysql> SELECT REGEXP_LIKE ('England Netherland Scotland', 'and$') AS Result; Here is the result: We can provide an additional parameter to refine the regular expression by using the match type arguments. See the below example where we are specifying a case-sensitive and case-insensitive match: mysql> SELECT REGEXP_LIKE ('India Indonesia', '^in', 'i') AS 'Case-Insensitive', REGEXP_LIKE ('India Indonesia', '^in', 'c') AS 'Case-Sensitive'; Here is the result:
Next TopicMySQL regexp_replace() Function
|