[英]regex remove specific text inside tag Notepad++
您好,我對編碼和嘗試了解正則表達式的工作方式有些陌生,
所以我正在使用產品處理XML文件,並想刪除標簽內的特定文本。 從下面的示例:
<descr><br/> <P>SOME RANDOM TEXT</P><br/> <P>&nbsp;</P><br/></descr>
我要刪除此部分:
<P>&nbsp;</P>
導致其干擾文本格式。 標記內可能會發生多次,因此我想每次都將其刪除。 我可以在Notepad ++中使用正則表達式嗎?
我能夠用此正則表達式來代替您:
(<descr>[\s\S]*?)<P>&nbsp;<\/P>([\s\S]*?<\/descr>)
替換為:
$1 SUCCESS $2
我用作輸入:
<descr><br/>
<P>SOME RANDOM TEXT</P><br/>
<P>&nbsp;</P><br/></descr>
<other><br/>
<P>SOME RANDOM TEXT</P><br/>
<P>&nbsp;</P><br/></other>
<descr><br/>
<P>SOME RANDOM TEXT</P><br/>
<P>&nbsp;</P><br/></descr>
它變成了:
<descr><br/>
<P>SOME RANDOM TEXT</P><br/>
SUCCESS <br/></descr>
<other><br/>
<P>SOME RANDOM TEXT</P><br/>
<P>&nbsp;</P><br/></other>
<descr><br/>
<P>SOME RANDOM TEXT</P><br/>
SUCCESS <br/></descr>
圖片:
解釋正則表達式:
( # start of group 1
<descr> # match the open tag
[\s\S] # space or non-space characters = anything
*? # the minimum amount till the next match
) # end of group 1
<P>&nbsp;<\/P> # your pattern, please note I had to escape the slash
( # start of group 2
[\s\S] # space or non-space characters = anything
*? # the minimum amount till the next match
<\/descr> # the closing tag, again look the escaped slash
) # end of group 2
和替換:
$1 SUCCESS $2 # $1 stores the value matched by the group 1
# $2 stores the value matched by the group 2
# The text " SUCCESS " was an example, it could be empty
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.