users@jsr311.java.net

Re: URI template with regexp using nested curly braces.

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Wed, 11 Mar 2009 12:01:19 +0100

On Mar 10, 2009, at 7:01 PM, Marc Hadley wrote:

> On Mar 10, 2009, at 1:51 PM, Sergey Beryozkin wrote:
>>>>
>>>> Can someone confirm please that as far as handling expressions
>>>> like "/area/{zipcode:[0-9]{5}}", it's up to
>>>> a given implementation how to handle them and no assumption can
>>>> be made that the default Java regexp should be used ?
>>>>
>>> How exactly an implementation supports regexs is up to the
>>> application but I think all implementations need to support the
>>> same regex syntax. I'd assumed the standard Java syntax would the
>>> one we'd use, it would be odd to pick another one.
>>
>> Thanks - the question is more about if the default Java regex
>> support is capable of handling the nested curly braces - it appears
>> that it's not quite easy to handle with the default support
>>
> Paul will have to confirm but, IIRC, for Jersey we had to resort to
> other means (bracket counting etc) to parse the @Path value.
>

Yes, if there is a regex expression present, then the expression will
be all the characters between the ':' and the final '}' that
corresponds to the first '{', not including any white space characters
directly after ':' or directly before the final '}'. For example, the
following case:

   "/area/{zipcode: [0-9]{5} }"

the regex of the path param "zipcode" is "[0-9]{5}".

The brackets need to be counted to ensure correct parsing termination.

If one needs to match the literal characters '{' or '}' then you need
to use the percent encoded form.

Paul.