Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.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 取代&&引用;加上&;amp&引用;使用clojure.string/replace_Regex_Clojure - Fatal编程技术网

Regex 取代&&引用;加上&;amp&引用;使用clojure.string/replace

Regex 取代&&引用;加上&;amp&引用;使用clojure.string/replace,regex,clojure,Regex,Clojure,非常不言自明。我有一个包含符号和字符的字符串,我需要用字符引用替换它 我尝试了多种正则表达式模式来尝试替换它,但都不起作用(这些只是少数): 最简单的方法是使用replace的字符串/字符串形式(而不是regex): 您可能还对环形编解码器感兴趣[Ring/Ring Codec“1.1.0”] 最简单的方法是使用replace的字符串/字符串形式(而不是regex): 您可能还对环形编解码器感兴趣[Ring/Ring Codec“1.1.0”] 我也试过了,但对我不起作用(s/replace s

非常不言自明。我有一个包含符号和字符的字符串,我需要用字符引用替换它

我尝试了多种正则表达式模式来尝试替换它,但都不起作用(这些只是少数):


最简单的方法是使用replace的字符串/字符串形式(而不是regex):

您可能还对环形编解码器感兴趣
[Ring/Ring Codec“1.1.0”]


最简单的方法是使用replace的字符串/字符串形式(而不是regex):

您可能还对环形编解码器感兴趣
[Ring/Ring Codec“1.1.0”]


我也试过了,但对我不起作用<代码>(s/replace string“&”&;”应该注意,它在REPL上可以正常工作,但由于某些原因不能在defn中工作。编辑:没关系,我的语法不好。这真的很好用!谢谢我也试过了,但对我不起作用<代码>(s/replace string“&”&;”应该注意,它在REPL上可以正常工作,但由于某些原因不能在defn中工作。编辑:没关系,我的语法不好。这真的很好用!谢谢这两个版本对我有效(clojure.string/replace“bean&cheese”#“\Q&\E”&;”
(clojure.string/replace“bean&cheese”#“&”&;”
非正则版本也有效
(clojure.string/replace“bean&cheese”&“&;”)
这两个版本对我有效
(clojure.string/replace“bean&cheese”\Q&;)“&;”
(clojure.string/replace“bean&cheese”#“&”和“&;”
非正则表达式版本也能工作
(clojure.string/replace“bean&cheese”&“&;”
(s/replace string #"\Q&\E" "&amp;")
(s/replace string #"\\Q&\\E" "&amp;")
(s/replace string #"\\&" "&amp;")
(s/replace string #"&" "&amp;")
(ns tst.demo.core
  (:require
    [clojure.string :as str]
    [ring.util.codec :as codec] ))

(def data "hello & goodbye")

(str/replace data "&" "&amp") => "hello &amp goodbye"
(codec/url-encode     data) => "hello%20%26%20goodbye"
(codec/percent-encode data) => "%68%65%6C%6C%6F%20%26%20%67%6F%6F%64%62%79%65"
(codec/form-encode    data) => "hello+%26+goodbye"