You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Rice Yeh <ri...@gmail.com> on 2010/08/04 05:38:24 UTC

The meaning of ([^/]+?)

Hi,
  In JAXRS spec, each uri template variable without regular expression
specified is matched by regular expression  ([^/]+?). I do not understand
the function of the ? mark in the group. Is it needed? That is, what is the
difference b/w "([^/]+)" and "([^/]+?)" ?  Any regular expression guru can
explain it?

Regards,
Rice

Re: The meaning of ([^/]+?)

Posted by Raphaël Flores <rf...@moulon.inra.fr>.
Le 04/08/2010 06:24, Rice Yeh a écrit :
> I use javascript to test and find
>
> "b123/c123".match(/([^/]+?)\/([^/]+?)/) = ["b123/c", "b123", "c"]
> "b123/c123".match(/([^/]+?)\/([^/]+)/) = ["b123/c123", "b123", "c123"]
> "b123/c123".match(/([^/]+)\/([^/]+)/) = ["b123/c123", "b123", "c123"]
> "b123/c123".match(/([^/]+)\/([^/]+?)/) =["b123/c", "b123", "c"]
>
> So the ? only have effects on the last path segment. But why the ? does not
> have effects on the first path element?
>
> Regards,
> Rice
>
> On Wed, Aug 4, 2010 at 11:38 AM, Rice Yeh <ri...@gmail.com> wrote:
>
>> Hi,
>>   In JAXRS spec, each uri template variable without regular expression
>> specified is matched by regular expression  ([^/]+?). I do not understand
>> the function of the ? mark in the group. Is it needed? That is, what is the
>> difference b/w "([^/]+)" and "([^/]+?)" ?  Any regular expression guru can
>> explain it?
>>
>> Regards,
>> Rice
Hi Rice,

Looking at Pattern.java:
http://download.oracle.com/javase/1.4.2/docs/api/java/util/regex/Pattern.html
It means: /X/+? /X/, one or more times

But there are subtile differences between quantifiers that Sun javadoc
would explain better than me. You can take a look here:
http://download.oracle.com/javase/tutorial/essential/regex/quant.html

BTW, using javascript might not make you getting certainly the same
result than Java regex API, you would prefer to test directly java API
since implementatino are not the same.

Regards,

-- 
Raphaël Flores
Téléphone : 01 69 33 23 76
UMR de Génétique Végétale, INRA, Univ. Paris-Sud, 
CNRS, AgroParisTech,  F-91190 Gif-sur-Yvette, France


Re: The meaning of ([^/]+?)

Posted by Rice Yeh <ri...@gmail.com>.
I use javascript to test and find

"b123/c123".match(/([^/]+?)\/([^/]+?)/) = ["b123/c", "b123", "c"]
"b123/c123".match(/([^/]+?)\/([^/]+)/) = ["b123/c123", "b123", "c123"]
"b123/c123".match(/([^/]+)\/([^/]+)/) = ["b123/c123", "b123", "c123"]
"b123/c123".match(/([^/]+)\/([^/]+?)/) =["b123/c", "b123", "c"]

So the ? only have effects on the last path segment. But why the ? does not
have effects on the first path element?

Regards,
Rice

On Wed, Aug 4, 2010 at 11:38 AM, Rice Yeh <ri...@gmail.com> wrote:

> Hi,
>   In JAXRS spec, each uri template variable without regular expression
> specified is matched by regular expression  ([^/]+?). I do not understand
> the function of the ? mark in the group. Is it needed? That is, what is the
> difference b/w "([^/]+)" and "([^/]+?)" ?  Any regular expression guru can
> explain it?
>
> Regards,
> Rice
>