Get the App
SLTechnology News&Howtos  ›  Database  › 

SQL regular expressions and methods of using regular expressions in mybatis

Shulou Source: shulou.com Published: 2022-05-31 23:42:38 10月05日 Update

Editor to share with you SQL regular expressions and mybatis in the use of regular expressions, I believe that most people do not know much, so share this article for your reference, I hope you will learn a lot after reading this article, let's go to understand it!

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 this article entitled "SQL regular expressions and ways 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 lowercase quantity article test method thing content writing name uppercase letter number not much single synonym place Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Xiaomi vpn Linux Huawei