- 2
- 0
- 约9.34千字
- 约 14页
- 2017-10-06 发布于河南
- 举报
如何在java中使用正则表达式(How do I use regular expressions in Java)
如何在java中使用正则表达式(How do I use regular expressions in Java)
How do I use regular expressions in Java to handle text data?
Release time: 2009.02.24 08:54 source: nokiaguy blog author: nokiaguy
[-IT technology reported] regular expression is a string, but unlike ordinary strings, regular expressions are abstractions of a set of similar strings, such as the following strings:
A98b, c0912d, c10b, , ab
We carefully analyze the above five strings, we can see that they have a common characteristic, is the first character must beaorc, the last character must bebord, and in the middle of the character is any number of digits (including 0 digits). Therefore, we can abstract the common features of these five strings, which leads to a regular expression: [ac]\\d*[bd]. And according to this regular expression, we can write infinite strings that satisfy the condition.
There are many ways to use regular expressions in Java, and the simplest is to use them together with strings. In String, there are four ways you can use regular expressions; they are matches, split, replaceAll, and replaceFirst.
One, matches method
The matches method can determine whether the current string matches a given regular expression. If match, returns true, otherwise returns false. The matches method is defined as follows:
Public Boolean matches (String regex)
As for the regular expressions given above, we can verify it with the following program.
String[], SS = new, String[]{, a98b, c0912d, c10b, , ab};
For (String, s:, SS)
System.out.println (s.matches ([ac]\\d*[bd]));
Output result:
True
True
True
True
True
Heres a brief explanation of the meaning of this regular expression. If we have learned the lexical analysis of the compiler principle, it is easy to understand the regular expressions above (because the expressions of regular expressions are similar to those in lexical analysis). As in [...] the equivalent or |, such as the [abcd] equivalent of a|b|c|d, which is a or B or C or D. I
您可能关注的文档
- 基金收益率计算(Fund yield calculation).doc
- 基础变形缝预溶模再造止水带防水方案研究(Study on water proof scheme of pre cast die stopping water for base deformation joint).doc
- 基金是这样投资运作股票的(That's how funds invest and operate stocks).doc
- 基础数学专业博士研究生培养方案(Training program for doctoral students in basic mathematics).doc
- 基金电商挖墙角门道薪酬不给力温情来凑数(The fund electricity supplier corners doorway pay suck warmth to dine).doc
- 塑料中常用透明原料的特性及注塑工艺(Characteristics and injection process of transparent material used in plastics).doc
- 塑料包装(Plastic packing).doc
- 基本能力复习知识点 美术部分(Basic ability, review knowledge, art section).doc
- 塑料大棚饲养肉鸡(Plastic greenhouse rearing broiler).doc
- 塑料成型与模具设计(Plastic forming and die design).doc
- 如何在阅读习作序列(How to read the workbook sequences).doc
- 如何培养看人、识人的能力(How to cultivate the ability to see people and know people).doc
- 如何做好生产主管(How to be a production supervisor).doc
- 如何处理老板更迭期(How do you handle boss change).doc
- 如何加强网络防护(How to strengthen network protection).doc
- 如何学习技术分析(三)-给喜欢我的朋友(How to learn technical analysis (three) - for a friend who likes me).doc
- 如何学习生物化学(How to study biochemistry).doc
- 如何学四级(How to learn grade four).doc
- 如何学好初二数学(How to learn math in junior high school).doc
- 如何实现ie自定义协议(How do I implement the IE custom protocol).doc
原创力文档

文档评论(0)