Mysql learning-mysql is required

Source: Internet
Author: User
Mysql learning-mysql is required. 1 is required for mysql. Chapter 9 is required:

Regular expressions are used to match special character sets. Mysql uses the where clause to provide preliminary support for regular expressions.

The keyword regexp is used to indicate the things following it as a regular expression.

(.) Is a regular expression symbol that matches any character:

mysql> select prod_name-> from products-> where prod_name regexp '.000'-> order by prod_name;+--------------+| prod_name|+--------------+| JetPack 1000 || JetPack 2000 |+--------------+2 rows in set (0.14 sec)

| Match character:

Indicates matching one of them

mysql> select prod_name-> from products-> where prod_name REGEXP '1000|2000'-> ORDER BY prod_name;+--------------+| prod_name|+--------------+| JetPack 1000 || JetPack 2000 |+--------------+2 rows in set (0.00 sec)


[] Match character: match one of several characters

2 rows in set (0.00 sec)mysql> select prod_name-> from products-> where prod_name regexp '[123] Ton'-> ;+-------------+| prod_name |+-------------+| 1 ton anvil || 2 ton anvil |+-------------+2 rows in set (0.00 sec)
mysql> select prod_name from products where prod_name regexp '[1-5] Ton';+--------------+| prod_name|+--------------+| .5 ton anvil || 1 ton anvil|| 2 ton anvil|+--------------+3 rows in set (0.02 sec)
mysql> select prod_name from products where prod_name regexp '[^1-3] Ton';+--------------+| prod_name|+--------------+| .5 ton anvil |+--------------+1 row in set (0.00 sec)


Special characters must be matched. // must be used as the leading character.

mysql> select prod_name from products where prod_name regexp '//.' ;+--------------+| prod_name|+--------------+| .5 ton anvil |+--------------+1 row in set (0.00 sec)


Matching character class:

mysql> select prod_name from products where prod_name REGEXP '//([0-9] sticks?//)' order by prod_name;+----------------+| prod_name|+----------------+| TNT (1 stick)|| TNT (5 sticks) |+----------------+2 rows in set (0.05 sec)mysql> select prod_name from products where prod_name REGEXP '[[:digit:]]{4}' order by prod_name;+--------------+| prod_name|+--------------+| JetPack 1000 || JetPack 2000 |+--------------+2 rows in set (0.00 sec)

Positioning operator usage:

mysql> select prod_name-> from products-> where prod_name REGEXP '^[0-9//.]'-> order by prod_name;+--------------+| prod_name|+--------------+| .5 ton anvil || 1 ton anvil|| 2 ton anvil|+--------------+3 rows in set (0.00 sec)

These are the usage of mysql 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.