[英]Java- how to ignore quotes inside quotes
我的json文件的value部分中有一些未轉義的引號,
"key":"value"
它像是
"text":"a personal persona as a street-smart "tough girl", which when
combined with raw talent","birthday":"19871108"
我想知道如何使用正則表達式使轉義報價成為我的價值部分? 使它看起來像
"text":"a personal persona as a street-smart \"tough girl\", which when
combined with raw talent","birthday":"19871108"
棘手的部分不是使用正則表達式查找引號,而是使用正則表達式查找未轉義的引號。
未轉義引號的定義是在其前面加上偶數個反斜杠(零反斜杠是最常見的情況)。
表情是這樣丑陋的:
(?<!(?:[^\\]|$)(?:\\{2})?\\)"
如果您認為這很糟糕,請查看Java中的轉義版本:
(?<!(?:[^\\\\]|$)(?:\\\\{2})?\\\\)\"
這實際上是查找尚未轉義的所有引號。 我使用的測試字符串是: Testing "unescaped". \\"escaped\\". \\\\"unescaped again\\\\"
Testing "unescaped". \\"escaped\\". \\\\"unescaped again\\\\"
Testing "unescaped". \\"escaped\\". \\\\"unescaped again\\\\"
regex只匹配第一和第三組引號,而不匹配轉義的第二組。
應該用\\"
或java \\\\\\"
代替。
試試看,讓我知道!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.