Get the App
SLTechnology News&Howtos  ›  Database  › 

Using regular expressions in MySQL

Shulou Source: shulou.com Published: 2022-06-01 10:50:11 10月03日 Update

The REGEXP function in MySQL can match regular expressions when using SQL, and when using some query conditions, you can use the REGEXP function to match the corresponding characters, which can replace many SQL functions that you are not familiar with or do not understand and are universal, so as to improve the daily work efficiency. It is very easy to use the REGEXP function under MySQL. For metacharacters of regular expressions, please see: the return values of the http://jim123.blog.51cto.com/4763600/1850919 quotient REGEXP function are Boolean values 0 and 1, that is, matching is 1, not 0, for example:

Mysql > SELECT'Monty' REGEXP'^ ostentatious Mushroom + | 'montyment.' REGEXP'^ o' | +-- + | 0 | +-- + 1 row in set (0.00 sec) mysql > SELECT 'Monty' REGEXP'^ Mechatronics Mushroom + | 'montysomething' REGEXP'^ M' | +-+ | 1 | +-+ 1 row in set (0.00 sec)

Of course, the REGEXP function can also be simplified to RLIKE, all the same.

Mysql > SELECT'Monty' RLIKE'^ masking; +-+ | 'Montmortal' RLIKE'^ M' | +-+ | 1 | +-+ 1 row in set (0.00 sec)

However, it is important to note that in MySQL, the REGEXP function can only be used for string type matching, not as a numeric value.

Tags: Function regular expression character mismatch metacharacter string Boolean efficiency numeric value is in condition type work query Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Shulou Technology Shulou Tech Info MariaDB macOS