tags:

views:

60

answers:

1

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.util.regex.Pattern says:

X?     X, once or not at all
X+     X, one or more times

So, what means +??

+8  A: 

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 :

Colin Hebert
to clarify, an ungreedy expression is one in which the shortest possible match is made, vs in a greedy one, the longest possible one is made.
PiPeep
Thanks, I didn't know that. But what does it mean in this case `([ˆ/]+?)`? As far as I understand everything is read up to the next `/`, would it be greedy or not.
deamon
In this case the `[ˆ/]+` part would be lazy and try to catch only one character (`+` is at least one) with [^/]*? nothing would be caught.
Colin Hebert