In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "Java regular expression related knowledge points what", in daily operation, I believe many people in Java regular expression related knowledge points what questions there are doubts, Xiaobian consulted all kinds of information, sorted out simple and easy to use operation methods, I hope to answer "Java regular expression related knowledge points what" doubts help! Next, please follow the small series to learn together!
\backslash
\tInterval ('\u0009')\nNew Line ('\u000A')\r Enter ('\u000D')\d Numeric 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 Single character [a-zA-Z_0 -9]\W Non-single character [^a-zA-Z_0 -9]\f Form break\e Escape\b Boundary of a word\B Boundary of a non-word\G End of previous match
Start with restrictions.
^java Conditional restriction starts with Java character $and ends with Java$ Conditional restriction to characters ending in java. To restrict an arbitrary character java.. The condition is limited to any two characters after java except newline
Add specific restrictions []
[a-z] Condition restricted to one character [A-Z] in the lowercase a to z range Condition limited to one character in the range of upper-case A to Z [a-zA-Z] Condition limited to one character in the range of lower-case a to z or upper-case A to Z [0-9] Condition restricted to one character in lowercase 0 to 9 [0-9a-z] Condition restricted to one character in lowercase 0 to 9 or a to z [0-9[a-z]] Condition restricted to one character in lowercase 0 to 9 or a to z (intersection)
Add ^to [] followed by additional restrictions [^]
[^a-z] Condition restricted to one character [^A-Z] in the range of non-lowercase a to z Condition restricted to one character in the range of non-upper case A to Z [^a-zA-Z] Condition restricted to one character in the range of non-lower case a to z or upper case A to Z [^0-9] Condition restricted to one character in the range non-lowercase 0 to 9 [^0-9a-z] Condition restricted to one character in the range non-lowercase 0 to 9 or a to z [^0-9[a-z]] Condition restricted to one character in the range non-lowercase 0 to 9 or a to z (intersection)
* can be used when the restriction is that a particular character appears more than 0 times
J* More than 0 J.* 0 or more arbitrary characters J.* D 0 or more characters between J and D
When the restriction is that a particular character appears more than once, you can use +
J+ More than one J.+ More than 1 arbitrary character J.+ D Any character between J and D
When the restriction is that a particular character appears 0 or more times, you can use?
JA? J or JA appears.
Limit to specified number of consecutive occurrences of character {a}
J{2} JJJ{3} JJJ
More than a word, and {a,}
J{3,} JJJ,JJJJ,JJJJJ,??? (More than 3 times J coexist)
More than one word, less than b {a,b}
J{3,5} JJJ or JJ or JJ
Either way.|
J|A J or AJava| Hello Java or Hello
A combination type is specified in ()
For example, if I query the data in index, I can write
When using the Pattern.compile function, you can add parameters that control the matching behavior of regular expressions:
Pattern Pattern.compile(String regex, int flag)
The value range of flag is as follows:
Pattern.CANON_EQ: A match is considered if and only if the canonical decomposition of both characters is identical. For example, after using this flag, the expression "a\u030A" will match "? "。By default, canonical equivalence is not considered.
Pattern.CASE_INSENSITIVE(? i): By default, case-insensitive matches only work with US-ASCII character sets. This flag allows expressions to match regardless of case. To match Unicode characters in ambiguous sizes, simply combine UNICODE_CASE with this flag.
Pattern.COMMENTS(? x): In this mode, matching ignores spaces (in regular expressions). Comments start with #and continue to the end of this line. Unix line mode can be enabled with embedded flags.
Pattern.DOTALL(? s): In this mode, the expression '. 'can match any character, including the terminator that represents a line. By default, the expression '. 'Doesn't match line terminator.
Pattern.MULTILINE(? m): In this pattern,'^' and '$' match the beginning and end of a line, respectively. Also,'^' still matches the beginning of the string, and '$' also matches the end of the string. By default, these two expressions match only the beginning and end of a string.
Pattern.UNICODE_CASE(? u): In this mode, if you also enable the CASE_INSENSITIVE flag, it performs case-insensitive matching on Unicode characters. By default, case-insensitive matching applies only to US-ASCII character sets.
Pattern.UNIX_LINES(? d): In this mode, only '\n' is considered a line stop, and with '. ','^', and'$'for matching.
Putting aside the concept of emptiness, here are a few simple Java regular use cases:
◆ For example, when the string contains validation
//Find strings that start with Java and end arbitrarily Pattern pattern = Pattern.compile("^Java.* ");Matcher matcher = pattern.matcher("Java is not human ");boolean b= matcher.matches();//Returns true if the condition is met, otherwise returns falseSystem.out.println(b);
◆ When dividing a string by multiple conditions
Pattern pattern = Pattern.compile("[, |]+");String[] strs = pattern.split("Java Hello World Java,Hello,,World|Sun");for (int i=0;i
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.