##1. Normal matching
“_” matches any single character
“%” matches any number of characters (including zero characters).
Example 1: To find names starting with "b":
SELECT * FROM pet WHERE name LIKE "b%";
Example 2: To find names that contain a " w" name:
SELECT * FROM pet WHERE name LIKE "%w%";
Example 3: To find names containing exactly 5 characters
SELECT * FROM pet WHERE name LIKE "_";
2, RegularExpressionMatching
When testing this type of pattern, use REGEXP and NOT REGEXP operations (or RLIKE and NOT RLIKE, they are synonyms).
"." Matches any single character.
"[...]" matches any characters within square brackets.
Example 1: "[abc]" matches "a", "b" or "c".
"-" is used to name a range of characters.
Example 2: "[a-z]" matches any lowercase letter, and "[0-9]" matches any number.
" * "matches zero or more things before it.
Example 3: "x*" matches any number of "x" characters, "[0-9]*" matches any number of digits, and ".*" matches any number of anything.
Regular expressions are case-sensitive, but if you wish, you can use a
character class to match both writings.
Example 4, "[aA]" matches lowercase or uppercase "a" and "[a-zA-Z]" matches any letter in both writing methods.
To position a pattern so that it must match the beginning or end of the value being tested, use "^" at the beginning of the pattern or "$" at the end of the pattern.
Example 5: To find names starting with "b"
SELECT * FROM pet WHERE name REGEXP "^[bB]";
Example 6: To find names ending with "fy" name
SELECT * FROM pet WHERE name REGEXP "fy$";
The above is the detailed content of Parsing fuzzy matches in MySQl. For more information, please follow other related articles on the PHP Chinese website!