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 <[email protected]> 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
