mysql使用正则表达式

来源:互联网 发布:阿里云csgo 编辑:程序博客网 时间:2024/05/27 00:46

mysql模糊查找基本的方式 :  

1. 用 %  _ 来过滤   %任意的字符 ,_ 当个的字符 

2. 同时支持正则表达式来过滤  :

The other type of pattern matching provided by MySQL uses extended regular expressions. When you test for a match for this type of pattern, use the REGEXP and NOT REGEXP operators (or RLIKE and NOT RLIKE, which are synonyms).

The following list describes some characteristics of extended regular expressions:

  • . matches any single character.

  • A character class [...] matches any character within the brackets. For example, [abc] matches ab, or c. To name a range of characters, use a dash. [a-z] matches any letter, whereas [0-9] matches any digit.

  • * matches zero or more instances of the thing preceding it. For example, x* matches any number of xcharacters, [0-9]* matches any number of digits, and .* matches any number of anything.

  • REGEXP pattern match succeeds if the pattern matches anywhere in the value being tested. (This differs from aLIKE pattern match, which succeeds only if the pattern matches the entire value.)

  • To anchor a pattern so that it must match the beginning or end of the value being tested, use ^ at the beginning or$ at the end of the pattern.

To demonstrate how extended regular expressions work, the LIKE queries shown previously are rewritten here to use REGEXP.


0 0
原创粉丝点击