Querying with a MySQL regular expression

Source: Internet
Author: User

MySQL provides preliminary support for regular expressions with a WHERE clause, allowing you to specify that the data retrieved by select is filtered with a regular expression.

The regexp is treated as a regular expression.

' N 'ORDER by Prod_name; ------return------+------------------------+|    Prod_name    |+------------------------+|  JetPack  |+------------------------+

Represents a match for any one character.

'. 'ORDER by Prod_name; ------------return-----------+-------------------------+|     Prod_name    |+-------------------------+|   JetPack  | |   JetPack  |+-------------------------+

Regular expression matching in MySQL is case-insensitive.

For case sensitivity, the binary keyword can be used.

such as: where Prod_name REGEXP BINARY ' JetPack. 000 '

To search for one of the two strings (or the string, or another string), use |.

| As an OR operator, represents one of the matches. More than two or conditions can be given.

' 1000 | 'ORDER by Prod_name; ------------return------------+----------------------+|  Prod_name   |+----------------------+| JetPack 1000 | | JetPack |+----------------------+

[] matches any single character.

[123] Defines a set of characters that means matching 1 or 2 or 3.

[] is another form of an or statement, [123] ton is the abbreviation for [1 | 2 | 3] ton.

^ Negates a character set and matches anything except the specified character. [^123] will match anything except these characters.

' [123] Ton 'ORDER by Prod_name; -------------return------------+--------------------+| Prod_name   |+--------------------+| 1 ton Anvil    | | 2 Ton anvil    |+--------------------+

Match Range

[0123456789] or [0-9] will match the number 0 to 9

[A-z] matches any letter symbol

' [1-5] Ton 'ORDER by Prod_name; ----------return-----------+-------------------+|  Prod_name |+-------------------+|  . 5 ton Anvil  | |  1 ton Anvil   | |  2 ton Anvil   |+-------------------+

Match Special characters

\ \ is the leading. That is, escaping. All characters that have a special meaning within a regular expression must be escaped in this manner.

\\-means Find-

\\. Represents a lookup.

‘\\.‘ ORDER by Vend_name; -------------return-------------+----------------------+|  Vend_name   |+----------------------+|  Furball INC    | +----------------------+

Like matches the entire string, and RegExp matches the substring.

Querying with a MySQL regular expression

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.