>> This works surprisingly well. Maybe there are more corner cases, >> but something already works with quick tests: > > Yes, not bad indeed. Did you find any corner cases? Below is the patch that works quite well for the most use cases. But unfortunately, there are still some unsolvable corner cases: when a file name is e.g. "aaxbbx" and the search regexp is "x$", then after removing "$", searching for "x" will find the first occurrence of "x", and will set match-data to it. Later code that uses string-match can adjust the found position to the last occurrence of "x". But it can't change match-data used by isearch. And using a temporary buffer won't help either to set the real buffer positions in match-data to the last "x". IOW, no post-processing can help the main search function to set match-data to the correct place that matches "x$" in the dired buffer (and file name doesn't always end at eol).