Take the 2-minute tour ×  I have the following regular
expression #^en/cities/(.*?)/$# and I want it to match anything,
but stop at the first slash.  I.e. it should match 'paris' but
not 'paris/france' if someone manages to type that URL.  I
thought I already had it as non-greedy with the questionmark,
but apparently not.  share|improve this question add comment  1
Answer  up vote 2 down vote accepted  Use a negated character
class.   In your regex the non-greediness failed because you
anchored the last slash to the end ($). Removing that would also
make your regex work:  share|improve this answer No need for the
? in your first example. –  Gumbo Nov 10 '12 at 9:47 @Gumbo -
Thanks, fixed. –  acheong87 Nov 10 '12 at 9:47 @ridgerunner -
Hm, I think you might be mistaken. The delimeter here is # (in
case that's what you missed) so the non-greedy quantifier must
seek until a / is matched. –  acheong87 Nov 10 '12 at 16:26 You
are absolutely correct. I did miss the /. Comment retracted.
Sorry bout that! +1 –  ridge