如何获取emacs正则表达式来识别包含和不包含行号的路径

时间:2013-09-05 23:01:40

标签: regex emacs elisp

尝试让emacs像这样按钮化按钮

/ NFS /路径/到/文件 / NFS /路径/到/ file_with_line_number:40

但不是带尾随冒号的路径 / NFS /路径/到/文件:

这不起作用

(defun buttonize-buffer-nfs-with-line ()
  "Turn all file paths with line numbers into buttons."
  (interactive)
  (save-excursion
    (goto-char (point-min))
    (while (re-search-forward "\(/nfs[^ \>\<\(\)\t\n,\'\";:]+?\)\|\(/nfs[^ \>\<\(\)\t\n,\'\";]+:[0-9]+?\)" nil t)
      (make-button (match-beginning 0) (match-end 0) :type 'find-file-button))))

(add-hook 'find-file-hook 'buttonize-buffer-nfs-with-line)

1 个答案:

答案 0 :(得分:4)

你需要反斜杠 - 逃避你的反斜杠。我从

开始
"/nfs[^ ><()\t\n,'\";:]+\\(:[0-9]+\\)?"