Atoms are matched sequentially, and each atom after the first should coincide at the position where the previous atom left a match. (The first atom is implicitly preceded by \A(?s:.)*? ) This means that .* / .*? cannot decide where he begins to compare; he only decides where he ceases to fit.
Example 1
This is not greed. \.ht displays the match at position 10, and at position 10 the minimum .*? may match and still contain the remaining match with the access/.htdf . In fact, this is the only thing .*? may match at position 10 and still have the rest of the pattern combination.
I think you want to remove this last part of the path if it starts with .ht , leaving the previous / in place. To do this, you can use one of the following actions:
s{/\.ht[^/]*$}{/}
or
s{/\K\.ht[^/]*$}{}
Example 2
This is not greed. b displays the match at position 2, and at position 2 the minimum .*? may match and still contain the remaining match with the cbc pattern. In fact, this is the only thing .*? can match at position 2 and still have the rest of the pattern matching.
You may be looking for
/b[^b]*$/
or
/b(?:(?!b).)*$/
ikegami
source share