簡體   English   中英

正則表達式-xml標記中的雙引號到雙引號轉義

[英]regex - double quote to double-double quote escape in xml tags

我有以下字符串,我想使用Regex Replace將所有引號(“)替換為雙引號(”“)。我只想替換>和<之間的那些引號。我該怎么做?

示例:之前

<Root>
    <Elem1>Hello "ds e"" 1293"</Elem1>
    <Elem2>sDieo " qqq "" dwe</Elem2>
</Root>

<Root>
    <Elem1>Hello ""ds e"""" 1293""</Elem1>
    <Elem2>sDieo "" qqq """" dwe</Elem2>
</Root>

請勿STRING.REPLACE,只能使用正則表達式

您可以搜索並替換:

/"(?![^<]*?>)/g

演示: https : //regex101.com/r/vZ9vW0/1

編輯:

包括正則表達式以防止匹配,但內部標記除外:

"(?=[^<>\n]*?<\/[^<>\n]*>)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM