简体   繁体   中英

Regular Expression with XML in notepad++

I have a xml like below:

<example id='1'>
   <val name='test1'/>
</example>
<example id='2' command='delete'>
   <val name='test2'/>
</example>
<example id='3'>
   <val name='test3'/>
</example>

I'm trying to use regular expressions within notepad++ to delete all example items with commands='delete' so that in the above example, test1 and test3 should be remaining.

I can easily do ones with no values like below but it's just the ones with values.

 <example id='1' command='delete' />

You can use

<example[^>]+command='delete'[^>]*>.*?<\/example>

(enable "dot matches newline")

and replace with the empty string.

https://regex101.com/r/e8E7cB/1

This does it:

<example[^\n]*delete.*?</example>\r\n

Remember to check "match newlines".

请使用搜索模式:“正则表达式”与“。匹配换行符”

<example.[^>]*command='delete'.*?</example>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM