开发者

'+' and '?' consecutively in a regex

开发者 https://www.devze.com 2023-01-15 11:05 出处:网络
The Java EE REST specifaction, JAX-RS, describes the translation of path variables to regexes, like in /customer/{id}.

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
0

精彩评论

暂无评论...
验证码 换一张
取 消