In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the knowledge of "the usage of Java regular expression matching pattern". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Greediness (greedy): maximum match
X?, X*, X+, X {n,} are the largest matches. For example, if you want to use "" to match "aaava abb", maybe what you expect is to match "", but the actual result will match "aava".
In Greediness mode, it will match as widely as possible until the whole content is matched, and when it is found that the match cannot be successful, it will start to fall back and narrow the match until the match is successful.
String test = "aaava abb"; String reg = ""; System.out.println (test.replaceAll (reg, "#"))
Output: a###abb
Reluctant (Laziness) (barely): minimum match
X-ray, X-ray, X {n,}? It is the smallest match, in fact, X {ncentine m}? And X {n}? It's a little redundant. Add after Greediness mode? It becomes the smallest match.
In Reluctant mode, as long as the match succeeds, you will no longer try to match a wider range of content.
String test = "aaava abb"; String reg = ""; System.out.println (test.replaceAll (reg, "#"))
Output: a###aava # abb
Unlike Greediness, the content is matched twice in Reluctant mode
Possessive (possessive): exact match
X matches +, X matches +, X {n,} + is an exact match, and adding + after the Greediness schema makes a perfect match.
The Possessive pattern is similar to Greediness in that they both try to match the widest range of content until the end of the content, but unlike Greediness, an exact match no longer tries to match a smaller range.
String test = "aaava abb"; String reg = ""; String test2 = ""; String reg2 = ""; System.out.println (test.replaceAll (reg, "#"); System.out.println (test2.replaceAll (reg2, "#")
Output: aaava abb
That's all for "Java regular expression matching pattern usage". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.