在以下 defun ...
中(defun re-backward-match-group (rexp &optional n)
"Grab the previous matches of regexp and return the contents of
the n match group (first group match if no n arg is specified)"
(save-excursion
(unless n
(setq n 1))
(when (numberp n)
(when (re-search-backward-lax-whitespace rexp)
(when (= (+ 2 (* n 2)) (length (match-data)))
(match-string-no-properties n))))))
如果未找到匹配项,则re-search-backward-lax-whitespace
我如何捕获该错误并返回nil或""
?
答案 0 :(得分:3)
re-search-backward-lax-whitespace
有一个可选的noerror
参数。
(re-search-backward-lax-whitespace rexp nil t)
不会发出错误信号。
对于更常见的错误处理,您可以使用ignore-errors
或condition-case
。有关后者的信息,请参阅