Javaregex 简明教程
Examples of Reluctant Quantifiers
懒惰量词指示搜索引擎从最短可能的字符串片段开始。一旦找到匹配项,引擎将继续;否则,它会向正在检查的字符串部分添加一个字符并搜索该部分,依此类推。此过程将一直持续到找到匹配项或用完整个字符串。以下是使用 Java 中的正则表达式编写懒惰量词的一些示例。
A reluctant quantifier indicates the search engine to start with the shortest possible piece of the string. Once match found, the engine continue; otherwise it adds one character to the section of the string being checked and search that, and so on. This process follows until it finds a match or the entire string has been used up. Following are various examples of Reluctant Quantifiers using regular expression in java.
Sr.No |
Construct & Matches |
1 |
X??X, once or not at all. |
2 |
X*?X, zero or more times |
3 |
X+?X, one or more times. |
4 |
X{n}?X, exactly n times. |
5 |
X{n,}?X, at least n times. |
6 |
X{n,m}?X, at least n but not more than m times |