Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.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:使用(字符串匹配)在字符串中查找子字符串_Regex_Emacs - Fatal编程技术网

Regex emacs:使用(字符串匹配)在字符串中查找子字符串

Regex emacs:使用(字符串匹配)在字符串中查找子字符串,regex,emacs,Regex,Emacs,为什么代码会产生相同的结果 (setq line "@c *##**@w{@ref{ФайлыКаталоги,, ФайлыКаталоги}}**##*") (string-match "*##**" line) ;(eval-last-sexp) => 3 (string-match "**##*" line) ;(eval-last-sexp) => 3 解决办法是使用星号屏蔽 (setq line "@c *##**@w{@ref{ФайлыКаталоги,, Файл

为什么代码会产生相同的结果

(setq line "@c *##**@w{@ref{ФайлыКаталоги,, ФайлыКаталоги}}**##*")
(string-match "*##**" line) ;(eval-last-sexp) => 3
(string-match "**##*" line) ;(eval-last-sexp) => 3

解决办法是使用星号屏蔽

(setq line "@c *##**@w{@ref{ФайлыКаталоги,, ФайлыКаталоги}}**##*")
(string-match "\\*##\\*\\*" line) ;(eval-last-sexp) => 3
(string-match "\\*\\*##\\*" line) ;(eval-last-sexp) => 47

除了您发现的以外,请注意每个regexp中的第一个星号(
*
)不是一个特殊的regexp字符。所以你不需要逃避它,去匹配一个星号。Elisp手册node中说:

请注意:对于历史兼容性,特殊字符为 如果他们在特殊情况下被视为普通人 意思没有意义

例如,
*foo
*
视为普通 因为没有前面的表达式,
*
可以对其进行操作。它是 依赖这种行为的不良实践;引用特殊字符 无论如何,不管它出现在哪里

所以是的,逃避它是可以的,但是要知道,第一个
*
永远不会特别行动,即使你没有逃避它。要进行特殊操作,
*
必须遵循以下内容。

用于轻松引用所有正则表达式特殊字符:
(字符串匹配(regexp quote“*##**”)行)