like LIKE requires the entire data to match, while REGEXP only requires a partial match. MySQL provides standard SQL pattern matching (like), as well as a format based on extended regular expression pattern matching similar to that used by Unix utilities such as vi, grep, and sed (regexp). To find names starting with "b": mysql> SELECT * FROM pet WHERE name LIKE "b%"; To find names ending with "fy": mysql> SELECT * FROM pet WHERE name LIKE "%fy"; To find names containing a "w": mysql> SELECT * FROM pet WHERE name LIKE "%w%"; To find names containing exactly 5 characters, use the "_" pattern character: mysql> SELECT * FROM pet WHERE name LIKE "_____"; REGEXP Another kind of matching is based on regular expressions. When you test for a match on such patterns, use the REGEXP and NOT REGEXP operators (or RLIKE and NOT RLIKE, which are synonyms). "." matches any single character. A character class "[...]" matches any character within the square brackets. For example, "[abc]" matches "a", "b", or "c". To name a range of characters, use a "-". "[az]" matches any lowercase letter, and "[0-9]" matches any digit. Regular expressions are case-sensitive , but if you wish, you can use a character class to match both. For example, "[aA]" matches lowercase or uppercase "a" and "[a-zA-Z]" matches any letter in either case. The pattern matches if it appears anywhere in the value being tested (SQL patterns match as long as they match the entire value). mysql> SELECT * FROM pet WHERE name REGEXP "^[bB]"; To find names ending with "fy", use "$" to match the end of the name: mysql> SELECT * FROM pet WHERE name REGEXP "fy$"; To find names containing a "w", use "[wW]" to match either lowercase or uppercase "w": mysql> SELECT * FROM pet WHERE name REGEXP "[wW]"; [^……], matches characters not contained in [], such as searching for names starting with w/z/s select name from table name where name regexp '^[^wzs]'; *, repeated 0 or more times, students familiar with javascript regular expressions know 'str*' can match st/str/strr/strrr... ?, repeated 0 or 1 times 'str?' can match st/str +, repeat 1 or more times 'str+' can match str/strr/strrr/strrrr... Compared with the regular expression in JavaScript, the regular expression here is a simplified version. There is no lazy matching/greedy matching. The syntax of \w\s\d is not supported in [], and Chinese is not supported. It is relatively simple . The above article about the usage of MYSQL pattern matching REGEXP and like is all the content that the editor shares with you. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM. You may also be interested in:
|
>>: Detailed explanation of Vue3.0 + TypeScript + Vite first experience
Table of contents Common payment methods in proje...
Table of contents Shallow copy Deep Copy Replenis...
Table of contents 1. Check the status of the serv...
First, your container must be running You can vie...
In cells, dark border colors can be defined indiv...
I struggled with a problem for a long time and re...
1. Dynamic Components <!DOCTYPE html> <h...
Table of contents 1 Version and planning 1.1 Vers...
Today I saw a little trick for HTML text escaping ...
Table of contents background explore Summarize ba...
The browser is probably the most familiar tool fo...
There are many types of auto-increment IDs used i...
Table of contents 1. JavaScript can change all HT...
If MySQL version 5.0 already exists on the machin...
How to deploy Oracle using Docker on Mac First in...