1. MySQL's regular expression simply makes a subset of the SQL language, which can match basic characters, strings. Select * fromWp_postswherePost_name REGEXP'Hello'; You can retrieve all rows in the post_name that contain Hello2. . Match any single character except \ nSelect * fromWp_postswherePost_name REGEXP'. og'; is a special character in a regular expression. It means matching one character, so bog,cog,dog and so on can match. Note: About case sensitivity: MySQL is an expression match (from version 3. at. 4) is case insensitive. If you want to be case sensitive, you should use the binary keyword, such as where Post_name REGEXPBINARY 'Hello.'3.^matches the starting position of the string, such as querying all the names of WangSelectName fromTable namewhereName REGEXP'^ Wang'; 4. $ matches the end position of the string, such as querying all names at the end of the name "Ming"
SelectName fromTable namewhereName REGEXP'Ming $'; 5. or match in order to search for one of multiple strings, using| Select * fromProductswherepro_id REGEXP'1000|2000'; This allows both 1000 and 2000 to match and return, of course, using multiple|you can match multiple strings6. [] Match several characters for example, this will match [0123456789] can match 0 to 9,[1-4][4-9] is also a legal range. In addition, the range is not necessarily numeric, [a-z] match any alphabetic character such as query out the name of the w/z/s beginningSELECTProd_name fromProductsWHEREProd_name REGEXP'^[wzs]'; 7.[^ ...], the match is not included in the[]characters, such as querying out names other than Chenmin.SELECTProd_name fromProductsWHEREProd_name REGEXP'[^chenmin]'; 8. Match Special characters using \ to escape \ \. ability to match. \\f page break \\n \\r carriage return \\t tab \ \ portrait tab note: to match \ itself, you need to use \9. Match character class[: Alnum:]Any letter and number (pass [a-Za-Z0-9])[: Alpha:]Any character (same as[a-za-z]) [: blank:]Spaces and tabs (same as[\\t]) [:d igit:]Any number (same as[0-9]) [: Lower:]any lowercase letter[: Upper:]any uppercase letter[: space:]any white space character, including spacesTen. Match multiple instances, about repeating meta characters*0 or more matches+1 or more matches (equals {1,})? 1 or more matches (equals {0,1}) {n} specifies the number of matches {n,} not less than the specified number of matches {n,m} matches the number of ranges (m less than 255) Example:SelectProd_name fromProductswhereProd_name REGEXP'[[:D igit:]]{4}'; As mentioned earlier,[:d igit:]matches any number, thus it is a geometry of the number. [[:d igit:]]{4Match any of the 4-bit numbers that are linked together, and of course the above example can be written regexp'[0-9][0-9][0-9][0-9]' One. Locator^the beginning of the text&End of text[[: <:]] The beginning of the word[[: :]The end of the word by using these locators enables the regexp to act like a
MySQL-Regular Expressions