On 21/03/2021 19:36, Maxim Nikulin wrote: > On 13/02/2021 11:38, Kyle Meyer wrote: >> +(defun org--open-file-format-spec (format specification) >> +  (with-temp-buffer >> +    (insert format) >> +    (goto-char (point-min)) >> +    (while (search-forward "%" nil t) >> +      (cond ((eq (char-after) ?%) >> +             (delete-char 1)) >> +            ((looking-at "[s0-9]") >> +             (replace-match >> +              (or (cdr (assoc (match-string 0) specification)) >> +                  (error "Invalid format string")) >> +              'fixed-case 'literal) >> +             (delete-region (1- (match-beginning 0)) (match-beginning >> 0))) It's pity that this issue has not fix yet. I have tried to implement another helper function. It is hardly usable outside of `org-open-file' (perhaps it is still suitable to make mailcap commands), but separate function makes the code testable. I hope, the attached patch fixes the problems with multiple regexp groups and with percent characters in replacement string. Notice that "\%", not "%%" is used to escape percent in mailcap, anyway neither variant was supported before.