'+' and '?' consecutively in a regex
The Java EE REST specifaction, JAX-RS, describes the translation of path variables to regexes, like in /customer/{id}
.
From JAX-RS 1.1 Spec, page 19:
Replace each URI template variable with a capturing group containing the specified regular expression or ‘([ˆ/]+?)’ if no regular expression is specified.
The Java API doc of java.ut开发者_Go百科il.regex.Pattern says:
X? X, once or not at all
X+ X, one or more times
So, what means +?
?
the ?
right after a +
or a *
means that it won't be greedy.
For example :
(.*)f
in "testftestf", the first group will match "testftest"
(.*?)f
in testftestf", the first group will match "test"
Resources :
- regular-expressions.info - laziness instead of greediness
精彩评论