Home > Database > Mysql Tutorial > body text

Parsing fuzzy matches in MySQl

怪我咯
Release: 2017-05-07 11:36:40
Original
1929 people have browsed it


##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$";



Parsing fuzzy matches in MySQl

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!