Regex clojure.string/replace与re-seq匹配的模式不匹配
为什么Regex clojure.string/replace与re-seq匹配的模式不匹配,regex,clojure,Regex,Clojure,为什么clojure.string/replace与\“[^\“]+\”模式不匹配,而re-seq与之匹配 (re-seq #"\"[^\"]+\"" "ab,\"helo,bro\",yo") => ("\"helo,bro\"") (clojure.string/replace "ab,\"helo,bro\",yo" #"\"[^\"]+\”" "") => "ab,\"helo,bro\",yo" 我希望replace删除匹配的模式。我缺少什么 感谢您的
clojure.string/replace
与\“[^\“]+\”
模式不匹配,而re-seq
与之匹配
(re-seq #"\"[^\"]+\"" "ab,\"helo,bro\",yo")
=> ("\"helo,bro\"")
(clojure.string/replace "ab,\"helo,bro\",yo" #"\"[^\"]+\”" "")
=> "ab,\"helo,bro\",yo"
我希望replace
删除匹配的模式。我缺少什么
感谢您的见解。您的正则表达式(可能是无意中)有所不同:在替换
选项中,您使用了\“
而不是\”
如果使用相同的正则表达式,它将按预期工作:
(def r #"\"[^\"]+\"")
(re-seq r "ab,\"helo,bro\",yo")
=> ("\"helo,bro\"")
(clojure.string/replace "ab,\"helo,bro\",yo" r "")
=> "ab,,yo"
您的正则表达式(可能是无意中)不同:在replace
选项中,您使用了\“
而不是\”
如果使用相同的正则表达式,它将按预期工作:
(def r #"\"[^\"]+\"")
(re-seq r "ab,\"helo,bro\",yo")
=> ("\"helo,bro\"")
(clojure.string/replace "ab,\"helo,bro\",yo" r "")
=> "ab,,yo"