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