MySQL Learning note (i)--use of regular expressions

Source: Internet
Author: User

The previous article describes database lookup filtering using some keywords with corresponding SQL statements, but the complexity of the WHERE clause itself increases as the complexity of filtering conditions increases. We can then use regular expressions to make matching lookups.

1. Basic character Matching

Select *  fromProductswhereProd_name RegExp' +' Order  byProd_name;--match the product name to 1000 of the character items that appearSelect *  fromProductswhereProd_name RegExp'.' Order  byProd_name;--To match any character, and a statement that matches any character ending with 000

2. Make or Match

Select *  from where ' 1000|2000 ' Order  by -- Match Product name contains 1000 or 2000 of the product information

3. Match one of several characters

Select *  from where [123] Order  by --

4. Match Range

Select *  from where [1-9] Order  by --

5. Match Special characters

Select *  from where ' \\. ' Order  by -- In regular expressions. To match any character, has a special meaning, we should use \ \ Escape when matching. 

Other elements that also need to be escaped:

\\f, \\n, \\r enter; \\t tabulation; \\v longitudinal tabulation

6. Matching multiple instances

Select  from where ' \ \ ([0-9] sticks?\\) ' Order  by Prod_name;  -- \ \ (means match (, [0-9] means match any character?) Indicates a match of 0 or 1 characters

*: Match 0 or more characters

+: Match 1 or more characters

? : matches 0 or 1 characters

^: Beginning of the text

$: End of text

MySQL Learning note (i)--use of regular expressions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.