Mysql like or regexp

broken image

This function can be used in the WHERE clause of database queries to return only those rows that contain the pattern: SELECT AlbumId, AlbumName Here’s an example where the regular expression specifies that the string must begin with certain characters: SELECT REGEXP_LIKE('Cat', '^Ca') Result Īnd here’s what happens if there’s no match: SELECT REGEXP_LIKE('Cat', '^Da') Result Example 3 – Match the Beginning of a String Our input string doesn’t contain this character and so 0 is returned.

broken image

In this case, our regular expression specifies that there should be one or more b characters in any sequence. Here’s an example where the input string doesn’t match the regular expression: SELECT REGEXP_LIKE('Cat', 'b+') Result The function returns 1 to indicate a match. In this case, our regular expression specifies any character in any sequence, so of course we get a match. Here’s a basic example: SELECT REGEXP_LIKE('Cat', '.*') Result For example, you can use match_type to specify case-sensitive matching or not. The optional match_type argument allows you to refine the regular expression.

broken image

Where expr is the input string and pat is the regular expression for which you’re testing the string against. The syntax goes like this: REGEXP_LIKE(expr, pat) The function returns 1 if the string matches the regular expression provided, and 0 if it doesn’t. In MySQL, the REGEXP_LIKE() function is used to determine whether or not a string matches a regular expression.

broken image