users@jersey.java.net

[Jersey] Re: default regex for path variables

From: Marek Potociar <marek.potociar_at_oracle.com>
Date: Wed, 28 Jan 2015 18:33:50 +0100

Hi Waclaw,

Interesting question, Unfortunately, your assumption is flawed. Reluctant quantifiers in Java work differently - see:
http://docs.oracle.com/javase/tutorial/essential/regex/quant.html <http://docs.oracle.com/javase/tutorial/essential/regex/quant.html>

TL;DR: Our regex says “find a match of a largest substring with one or more non-slash chars, by starting with an empty string and adding one character at a time until you cannot add another matching character”, i.e. match reluctantly. It does not however mean “find a smallest matching substring and finish”…

Cheers,
Marek


> On 28 Jan 2015, at 11:37, Waclaw Kusnierczyk <waclaw.kusnierczyk_at_gmail.com> wrote:
>
> In sec. 3.1.1 of https://jersey.java.net/documentation/latest/jaxrs-resources.html <https://jersey.java.net/documentation/latest/jaxrs-resources.html>, you state that the default regular expression for path variables is "[^/]+?". This seems wrong. I assume what you mean is "one or more non-slash characters"; what the above says, is "one or more non-slash characters, but as few as possible"---effectively, just one non-slash character. Didn't you mean "[^/]+"?
>
> Best,
> Wacek