This article mainly introduces the SQL regular expression and the use of regular expressions in the MyBatis method, very good, with a certain reference value, the need for friends can refer to the following
Other types of pattern matching that MySQL provides are the use of extended regular expressions.
When you test for this type of pattern, use the regexp and not regexp operators (or rlike and not rlike, which are synonyms).
Some of the characters that extend the regular expression are:
“.” matches any single character.
A character class "[...]" Matches any character within the square brackets. For example, "[ABC]" matches "a", "B", or "C". To name a range of characters, use a "-". "[A-z]" matches any lowercase letter, while "[0-9]" matches any number.
"*" matches 0 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 to, you can use a character class to match two types of writing. For example, "[AA]" matches lowercase or uppercase "a" and "[A-za-z]" matches any letter of two notation.
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 an extended regular expression works, the like query shown above uses RegExp rewrite below:
To find the name beginning with "B", use "^" to match the beginning of the name and "[BB]" to match the lowercase or uppercase "B":
Mysql> select * FROM pet WHERE name REGEXP "^[BB]";
Use regular Expressions in Myabtis
<select id= "provincelists" resultmap= "Basecountry" parametertype= "java.lang.String" > select Code,label from institution where admlvl = ' 2 ' and Code REGEXP "[0-9]*\. [0-9]* "</select> <select id=" citylists "resultmap=" Basecountry "parametertype=" java.lang.String "> Select Code,label from institution where admlvl = ' 3 ' and Code REGEXP "[0-9]*\. [0-9]*\. [0-9]* "</select> <select id=" countylists "resultmap=" Basecountry "parametertype=" java.lang.String "> Select Code,label from institution where admlvl = ' 4 ' and Code REGEXP "[0-9]*\. [0-9]*\. [0-9]*\. [0-9]*]; </select>