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

时间:2020-12-28 19:22:13

I am trying to replace:

我想替换:

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

sum(“PUBLIC”。“ORDERS”。“TOTAL”)AS“sum”

In the string:

在字符串中:

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

选择“PUBLIC”。“ORDERS”。“TAX”作为“TAX”,sum(“PUBLIC”。“ORDERS”。“TOTAL”)AS“sum”from“PUBLIC”。“ORDERS”GROUP BY“PUBLIC”。“订单“。”税“订购”公共“。”订单“。”税“ASC

The issue is presence of quotes ", parentheses ( ) and dots .

问题是存在引号“,括号()和点。

1 个解决方案

#1


1  

The quotes just need to have a backslash in front of them:

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

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"

#1


1  

The quotes just need to have a backslash in front of them:

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

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"