Java – * and * * differences
•
Java
*What's the difference between and * *? Why** When using pattern Did not compile when compiling (". * *");?
Solution
See the Java quantifiers reference:
Greedy Reluctant Possessive Meaning X? X?? X?+ X,once or not at all X* X*? X*+ X,zero or more times X+ X+? X++ X,one or more times X{n} X{n}? X{n}+ X,exactly n times X{n,} X{n,}? X{n,}+ X,at least n times X{n,m} X{n,m}? X{n,m}+ X,at least n but not more than m times
There is no * * quantifier When you use after, * or? (or even {n, m}), you can create possessive quantifiers (see the table above), but adding * quantifiers after * is considered a user error
That's why* Will match 0 characters (without pattern.dotall modifier) and. Except newline character** Throw an exception
Note that online regular expression testers will also warn you of this problem: dangling meta character '*' near index 2. * *^ (the same warning appears in ocpsoft regex tester)
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码