< type= "Text/javascript" > is well known, in the process of development, inevitably encounter the need to match, find, replace, judge the occurrence of strings, and these circumstances are sometimes more complex, if the pure coding method, often waste the programmer's time and energy. Therefore, learning and using regular expressions has become the main means to solve this contradiction.
As you all know, regular expressions are a specification that can be used for pattern matching and substitution, and a regular expression is a text pattern consisting of ordinary characters (such as characters A through Z) and special characters (metacharacters), which describe one or more strings to match when looking for a text body. A regular expression, as a template, matches a character pattern to the string you are searching for.
Since jdk1.4 launched the Java.util.regex package, we have provided a good Java regular Expression application platform.
Because the regular expression is a very complex system, so I just cite some of the concepts of entry, more please refer to the relevant books and self-exploration.
\ back Slash
\ t interval (' \u0009 ')
\ n line break (' \u000a ')
\ r Enter (' \u000d ')
\d number equivalent to [0-9]
\d non-numeric equivalent to [^0-9]
\s blank symbol [\t\n\x0b\f\r]
\s non-blank symbol [^\t\n\x0b\f\r]
\w individual characters [a-za-z_0-9]
\w non-individual characters [^a-za-z_0-9]
\f Page Break
\e Escape
\b The boundary of a word
\b A non-word boundary
\g the end of a previous match
^ Opening for the limit
^java conditions are limited to Java as the starting character
For the limit end Java for the limit end Java condition is limited to with Java as the end character
. conditional limit except \ n any single character
Java.. Any two characters in addition to line breaks after a condition is restricted to Java
Add a specific restriction condition "[]"
[A-Z] condition is limited to one character in the lowercase a to Z range
[A-Z] condition is limited to one character in the uppercase A to Z range
[A-za-z] Condition limited to one character in lowercase A to Z or uppercase A to Z range
[0-9] conditions limited to one character in the lowercase 0 to 9 range
[0-9a-z] conditions are limited to one character in the lowercase 0 to 9 or a to Z range
[0-9[a-z]] condition limited to one character (intersection) in lowercase 0 to 9 or a to Z range
[] Add ^ after add again limit condition "[^]"
[^a-z] Condition limited to one character in the non-lowercase a to Z range
[^a-z] condition is limited to one character in the non-uppercase A to Z range
[^a-za-z] conditions are limited to one character in the range of non-lowercase A to Z or uppercase A to Z
[^0-9] Condition limited to one character in a non-lowercase 0 to 9 range
[^0-9a-z] conditions are limited to one character in a non-lowercase 0 to 9 or a to Z range
[^0-9[a-z]] condition limited to one character (intersection) in non-lowercase 0 to 9 or a to Z range
You can use "*" when the limit is more than 0 times for a specific character
J* more than 0 J
. * More than 0 any characters
J.*d 0 or more characters between J and D
You can use "+" when the limit is more than 1 times for a specific character
j+ more than 1 J
. + 1 + any character
J.+d 1 or more characters between J and D
You can use "?" when the limit is 0 or 1 times for a specific character
MAX J or Ja appears
Limit to consecutive occurrences of the specified number of characters "{a}"
J{2} JJ
J{3} JJJ
Text more than a, and "{a,}"
J{3,} jjj,jjjj,jjjjj,??? (3 times above J co-exist)
More than one word, B below "{a,b}"
j{3,5} JJJ or JJJJ or JJJJJ
Take a "|" of both.
j| A J or a
java| Hello java or hello
A combination type is specified in "()"
For example, I query the data in the middle of index, can write