http://www.perlmonks.org?node_id=1062594


in reply to Re: Regex problem - (non)greedy?
in thread Regex problem - (non)greedy?

I expect that doesn't give the intended results for any of the following:

"cdghi" "cd ghi ghi"

Furthermore, that pattern won't help if we wants to go on to handle either of the following:

"cd XXX ghi cd YYY ghi" "cd XXX cd YYY ghi ZZZ ghi"

By the way, you really want to add a leading ^ to that to speed things up greatly when the pattern doesn't match.