users@jsr311.java.net

Re: Few question about custom regular expressions

From: Marc Hadley <Marc.Hadley_at_Sun.COM>
Date: Wed, 03 Dec 2008 08:48:44 -0500

On Dec 3, 2008, at 8:33 AM, Sergey Beryozkin wrote:

> Hi,
>>>
>> E.g. if the URI template contains a literal '.' then you have to
>> escape it so it represents a literal . in the resulting regex and
>> not the regex character class that represents any char. E.g.
>> @Path("a.b") converted to a regex using 3.7.3 is "a\.b(.*)?" since
>> you have to escape the '.'.
>>
>
> So how can I find out if the user meant to say with @Path("a.b")
>
> "path should start from a, followed by any single word character,
> and finished with b". Well, possibky using
> @Path("a\\wb") would be better but @Path("a.b") also works.
>
To do that the user would have to put in a dummy variable like this:

@Path("a{something:.}b"). You can only use regex stuff inside a
variable, not in the literal part of a path template.

> I have this test code :
>
> URITemplate uriTemplate = new URITemplate("/books/{bookId:...\\.}");
> assertTrue(uriTemplate.match("/books/123."));
> assertTrue(uriTemplate.match("/books/abc."));
> assertFalse(uriTemplate.match("/books/abcd"));
> assertFalse(uriTemplate.match("/books/abc"));
>
>
> This regular expressions allows for any 3 characters followed by
> literal '.' and it's a user code which controls what should happen.
> 3.7.3 (without any escaping) produces "/books/(...\.)(/.*)?". Note
> that a 3rd assertion fails as 'd' is not '.', while the fourth one
> fails due to a missing '.'.
>
That all looks correct.

> Am I still missing the point ?
>
That I can't say ;-). What about the above isn't clear ?

Marc.

---
Marc Hadley <marc.hadley at sun.com>
CTO Office, Sun Microsystems.