users@jsr311.java.net

Re: Few question about custom regular expressions

From: Marc Hadley <Marc.Hadley_at_Sun.COM>
Date: Wed, 03 Dec 2008 10:23:22 -0500

On Dec 3, 2008, at 9:14 AM, Sergey Beryozkin wrote:

>>> @Path("a.b")
>
>> I need to have this test passing now :
>>
>> URITemplate uriTemplate = new URITemplate("/books/a.b");
>> assertTrue(uriTemplate.match("/books/a.b"));
>> assertFail(uriTemplate.match("/books/abc"));
>
> so I did this test and it works without me modifying any code, the
> resulting regular expression is
>
> "/books/a.b(/.*)?"
>
> This expression requires that only "a.b" is accepted.
>
> So, sorry I'm feeling silly, I'm still in the dark as to why I need
> to escape '.' in the above Path's value if the goal is to ensure
> that only a literal '.' is allowed between 'a' and 'b'.
>
Try assertFail(uriTemplate.match("/books/acb"));

That should fail but will not if you don't escape the '.' in the regex.

/books/abc will fail anyway because of the final 'c' which doesn't
match the final 'b' in the template.

Marc.

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