users@jsr311.java.net

Re: Few question about custom regular expressions

From: Sergey Beryozkin <sergey.beryozkin_at_progress.com>
Date: Wed, 3 Dec 2008 13:33:49 -0000

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.

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 '.'.

Am I still missing the point ?

Cheers, Sergey