在clojure中查找并​​替换带引号和括号的字符串

时间:2016-09-10 01:59:49

标签: regex clojure

我想替换:

http://ipAddress:8080/appName/

在字符串中:

sum("PUBLIC"."ORDERS"."TOTAL") AS "sum"

问题是引用SELECT "PUBLIC"."ORDERS"."TAX" AS "TAX", sum("PUBLIC"."ORDERS"."TOTAL") AS "sum" FROM "PUBLIC"."ORDERS" GROUP BY "PUBLIC"."ORDERS"."TAX" ORDER BY "PUBLIC"."ORDERS"."TAX" ASC,括号" (和点)

1 个答案:

答案 0 :(得分:1)

引号只需要在它们前面加一个反斜杠:

user=> (def s "SELECT \"PUBLIC\".\"ORDERS\".\"TAX\" AS \"TAX\", sum(\"PUBLIC\".\"ORDERS\".\"TOTAL\") AS \"sum\" FROM \"PUBLIC\".\"ORDERS\" GROUP BY \"PUBLIC\".\"ORDERS\".\"TAX\" ORDER BY \"PUBLIC\".\"ORDERS\".\"TAX\" ASC")

#'user/s

user=> (.replace s "sum(\"PUBLIC\".\"ORDERS\".\"TOTAL\") AS \"sum\"" "new string")

"SELECT \"PUBLIC\".\"ORDERS\".\"TAX\" AS \"TAX\", new string FROM \"PUBLIC\".\"ORDERS\" GROUP BY \"PUBLIC\".\"ORDERS\".\"TAX\" ORDER BY \"PUBLIC\".\"ORDERS\".\"TAX\" ASC"