Difference between "\\ d +" and "\\ d ++" in java regex

In java, what's the difference between "\\d+" and "\\d++" ? I know ++ is an possessive quantifier, but what's the difference in matching a number string? Which line can match "\\d+" but cannot with "\\d++" ? The potential quantifier seems to matter only with the ".*" Quantifier. It's true?

+7
source share
2 answers

Essential quantifiers will not indent, even if some indentation is required for full compliance.

So, for example, the regular expression \d++0 never match any input, because \d++ will match all digits, including 0 , which must match the last character of the regular expression.

+10
source

\ d + Tools:
\d means a digit (a character in the range 0-9), and + means 1 or more times. So, \d+ - 1 or more digits.

\ d ++ Tools from Quanters

This is called possessive quantifiers, and they always eat the entire input line, trying once (and only once) to match. Unlike greedy quantifiers, possessive quantifiers never back down, even if this allows a coincidence of complete success.

0
source

All Articles