in reply to Re: regex greedy range
in thread regex greedy range

You forgot a bunch of question marks, and you're using capturing when you only need grouping:

m!((((\w+/)\w+/)\w+/)\w+/?)!;
should be:
m!((?:(?:(?:\w+/)?\w+/)?\w+/)?\w+/?)!;
but that requires lots of backtracking, so I think it's less efficient than:
m!(\w+(?:/\w+(?:/\w+(?:/\w+)?)?)?)!;
which only requires a single character lookahead.

Replies are listed 'Best First'.
Re^3: regex greedy range
by Aristotle (Chancellor) on Sep 16, 2004 at 23:47 UTC

    No, I didn't forgot the question marks, and I used capturing parens on purpose. But I was answering a different question than was actually asked.

    It could actually turn out more efficient with a slight variation:

    m!((?>(?>(?>\w+/)?\w+/)?\w+/)?\w+/?)!;

    I haven't done any benchmarks though.

    Makeshifts last the longest.