Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.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_Regex Negation - Fatal编程技术网

Regex 优雅的正则表达式,可匹配所有标点符号,但不匹配'&引用;在emacs Lisp中?

Regex 优雅的正则表达式,可匹配所有标点符号,但不匹配'&引用;在emacs Lisp中?,regex,regex-negation,Regex,Regex Negation,我想匹配所有标点符号,但不是“””,如“我是””。例如,在下面的句子中: I'm a student, but I'm also working. ^not match ^match ^not ^match 我可以使用“[[:punct:][]+”匹配所有标点符号,但我很难从匹配模式中排除“”” 当然,我可以用下面这样的东西来通过列举来表达,但这太单调了,尤其是考虑到中文的标点符号。 “[,.?!]” 请提出一个更优雅的解决方案 提前感谢, Yu如果您的regex f

我想匹配所有标点符号,但不是“
”,如“
我是”
”。例如,在下面的句子中:

I'm a student, but I'm also working. 
 ^not match  ^match ^not           ^match
我可以使用“
[[:punct:][]+
”匹配所有标点符号,但我很难从匹配模式中排除“

当然,我可以用下面这样的东西来通过列举来表达,但这太单调了,尤其是考虑到中文的标点符号。 “
[,.?!]

请提出一个更优雅的解决方案

提前感谢,


Yu

如果您的regex flavor支持环顾四周,您可以这样做:

(?!')[[:punct:]]

通俗易懂:如果展望未来时没有单引号,请匹配任何标点符号。

感谢巴特的回答和您的所有评论。受巴特的启发,我检查了一下emacs似乎仍然不支持前瞻。但本着精神,我编写了以下代码:

(取消字符串匹配但排除(regexp字符串排除&可选开始)

返回字符串中regexp的第一个匹配开始的索引,或nil, 但在排除中排除正则表达式。 如果
case fold search'为非nil,则匹配将忽略大小写。
如果第三个参数start为非nil,则在字符串中的该索引处开始搜索。
对于超出匹配的第一个字符的索引,do(匹配结束0)。
match end'和'match start'还提供子字符串的索引 由模式中的括号结构匹配

可以使用函数“match string”提取子字符串 由regexp中的括号结构匹配。“

(let((数据为零))

)

所以对于(?!)[[:punct:]string“'”)的等价表达式

是的

(字符串匹配但不包括“[:punct:][”字符串“”)

这可以完成任务,但没有那么优雅。它应该是对emacs的一个小添加,以使其成为一个内置支持

emacs现在支持角色类

再次感谢


Yu

Emacs Lisp有自己独特的正则表达式语法,我怀疑它是否支持lookarounds.:-)我扫描了这个问题,找到了Yu正在使用的regex实现(其中没有提到任何),但忘记了查看帖子的标题…:)是的,事实上我也很困惑:gnu.org上的Emacs手册上说“字符类不受支持,所以举例来说,你需要使用“[0-9]”而不是“[:digit:][]””,然而Yu说“[[:punt:][]”是有效的。
(and (string-match regexp string start)

   ;; keep the match-data for recovery at the end. 

   (setq data (match-data))

   (not (string-match (concat "[" exclusion "]") (match-string 0 string)))

   (progn (set-match-data data) t) ; To recover the match data, and make sure it produces t as returned value

   (match-beginning 0)

   ))