You can use regular expressions in the WHERE clause by using the RLIKE or REGEXP operators. There are many ways to use REGEXP, refer to https://dev.mysql.com/doc/refman/8.0/en/regexp.html for more examples:
Expression |
Description |
* |
Zero or more repetitions |
+ |
One or more repetitions |
? |
Optional character |
. |
Any character |
\. |
Period |
^ |
Starts with |
$ |
Ends with |
[abc] |
Only a, b, or c |
[^abc] |
Neither a, b, nor c |
[a-z] |
Characters a to z |
[0-9] |
Numbers 0 to 9 |
^...$ |
Starts and ends |
\d |
Any digit |
\D |
Any non-digit character |
\s |
Any whitespace |
\S |
Any non-whitespace character |
\w |
Any alphanumeric character |
\W |
Any non-alphanumeric ... |