Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex emacs lisp中的空字符串正则表达式_Regex_Emacs_Elisp - Fatal编程技术网

Regex emacs lisp中的空字符串正则表达式

Regex emacs lisp中的空字符串正则表达式,regex,emacs,elisp,Regex,Emacs,Elisp,我有这段代码来查找区域中的空字符串 (defun replace-in-region (start end) (interactive "r") (let ((region-text (buffer-substring start end)) (temp nil)) (delete-region start end) (setq temp (replace-regexp-in-string "\\_>" "X" region-text)) (

我有这段代码来查找区域中的空字符串

(defun replace-in-region (start end)
  (interactive "r")
  (let ((region-text (buffer-substring start end))
        (temp nil))
    (delete-region start end)
    (setq temp (replace-regexp-in-string "\\_>" "X" region-text))
    (insert temp)))
当我在一个区域上使用它时,它会将其清除,不管所述区域的内容如何,并给出错误“Args超出范围:4,4”

在包含以下内容的区域中使用
query replace regexp
时:

abcd abcd
abcd 11.11
regexp
\\u>
(请注意,只有一个反斜杠)和rep
X
四次出现后的结果区域被替换为:

abcdX abcdX
abcdX 11.11X

我这里缺少什么?

它看起来像是
中的一个bug,替换字符串中的regexp

它首先匹配原始字符串中的regexp。例如,它查找“abcd”的结尾。然后它选择匹配的子字符串,出于我不知道的原因,在子字符串上重做匹配。在这种情况下,匹配失败(因为它不再跟在单词后面),但跟在它后面的代码假定匹配成功并且匹配数据已更新

请使用
M-x report emacs bug
将此报告为bug

我建议您用一个简单的循环替换对
replace regexp in string
的调用。事实上,我建议你不要剪断绳子,做如下事情:

(defun my-replace-in-region (start end)
  (interactive "r")
  (save-excursion
    (goto-char start)
    (setq end (copy-marker end))
    (while (re-search-forward "\\_>" end t)
      (insert "X")
      ;; Ensure that the regexp doesn't match the newly inserted
      ;; character.
      (forward-char))))

它看起来像是
替换字符串中的regexp
中的错误

它首先匹配原始字符串中的regexp。例如,它查找“abcd”的结尾。然后它选择匹配的子字符串,出于我不知道的原因,在子字符串上重做匹配。在这种情况下,匹配失败(因为它不再跟在单词后面),但跟在它后面的代码假定匹配成功并且匹配数据已更新

请使用
M-x report emacs bug
将此报告为bug

我建议您用一个简单的循环替换对
replace regexp in string
的调用。事实上,我建议你不要剪断绳子,做如下事情:

(defun my-replace-in-region (start end)
  (interactive "r")
  (save-excursion
    (goto-char start)
    (setq end (copy-marker end))
    (while (re-search-forward "\\_>" end t)
      (insert "X")
      ;; Ensure that the regexp doesn't match the newly inserted
      ;; character.
      (forward-char))))

顺便说一句,
buffer substring
delete region
的组合有自己的功能:
delete and extract region
。顺便说一句,
buffer substring
delete region
的组合有自己的功能:
delete and extract region