Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

SQL regular expressions and how to use regular expressions in mybatis

Shulou Source: shulou.com Published: 2022-06-02 05:19:22 09月27日 Update

This article mainly shows you "SQL regular expressions and how to use regular expressions in mybatis", the content is easy to understand, clear, hope to help you solve your doubts, the following let Xiaobian lead you to study and learn "SQL regular expressions and how to use regular expressions in mybatis" this article.

The other type of pattern matching provided by mysql is using extended regular expressions.

When you do matching tests on such patterns, use the REGEXP and NOT REGEXP operators (or RLIKE and NOT RLIKE, which are synonyms).

Some of the characters that extend regular expressions are:

"." Matches any single character.

A character class "[.]" Matches any character in square brackets. For example, "[abc]" matches "a", "b", or "c". To name a range of characters, use a "-". "[amurz]" matches any lowercase letter, while "[0-9]" matches any number.

"*" matches zero or more things in front of it. For example, "x*" matches any number of "x" characters, "[0-9] *" matches any number of numbers, and ". *" matches any number of anything.

Regular expressions are case-sensitive, but if you want, you can use one character class to match both. For example, "[aA]" matches lowercase or uppercase "a" and "[a-zA-Z]" matches any of the two letters.

If it appears anywhere in the value being tested, the pattern matches (as long as they match the entire value, the SQL pattern matches).

To locate a pattern so that it must match the beginning or end of the value being tested, use "^" at the beginning of the pattern or "$" at the end of the pattern.

To illustrate how extended regular expressions work, the LIKE query shown above is rewritten using REGEXP below:

To find names that start with "b", use "^" to match the beginning of the name and "[bB]" to match lowercase or uppercase "b":

Mysql > SELECT * FROM pet WHERE name REGEXP "^ [bB]"

Use regular expressions in Myabtis yourself

Select code,label from institution where admlvl ='2' and code REGEXP "[0-9] *. [0-9] *" select code,label from institution where admlvl ='3' and code REGEXP "[0-9] *. [0-9] *. [0-9] *" select code,label from institution where admlvl ='4' and code REGEXP "[0-9] *. [0-9] *. [0-9] *\. [0-9] *" These are all the contents of the article "SQL regular expressions and how to use regular expressions in mybatis". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Regular expression character pattern content lowercase quantity article test thing writing name uppercase letter number learning help single synonym place Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple MariaDB macOS Shulou Tech Info NVidia