[英]regex remove specific text inside tag Notepad++
Hello i'm a bit new to coding and trying to understand how regular expressions works, 您好,我对编码和尝试了解正则表达式的工作方式有些陌生,
so i'm working on an XML file with products and want to delete specific text inside a tag. 所以我正在使用产品处理XML文件,并想删除标签内的特定文本。 From the example below:
从下面的示例:
<descr><br/> <P>SOME RANDOM TEXT</P><br/> <P>&nbsp;</P><br/></descr>
i want to remove this part: 我要删除此部分:
<P>&nbsp;</P>
cause its interfering with the text format. 导致其干扰文本格式。 This may happen multiple times within the tag, so i want to remove it every time.
标记内可能会发生多次,因此我想每次都将其删除。 Can i do this with a regex in Notepad++ ?
我可以在Notepad ++中使用正则表达式吗?
I was able to do your replace with this regex: 我能够用此正则表达式来代替您:
(<descr>[\s\S]*?)<P>&nbsp;<\/P>([\s\S]*?<\/descr>)
Replacing it by: 替换为:
$1 SUCCESS $2
I used as input: 我用作输入:
<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>
And it became: 它变成了:
<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>
Image: 图片:
Explaining the regex: 解释正则表达式:
( # 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
And the replace: 和替换:
$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.