简体   繁体   中英

Regular expression to match non empty xml tags using Notepad++

The xml file contain multiple tags, some of which has a value and some are blank, like

<main>
  <text></text> <text>   </text> <text></text> <text>test str</text>
  <text></text>
</main>

as you can see that there is only one non empty text tag, In npp how do I find such non empty tags in xml using regular expressions. I don't want the expression to match the tags with white-spaces.

So after performing find it should match <text>test str</text>

I have tried <text>(\S+)</text> but this is not working.

You could use this regex, which looks for a <text> tag followed by some number of spaces then a non-space character, using a negative lookahead to assert that we are not at the closing tag:

<text>\s*(?!</text>)\S.*?</text>

Demo on regex101

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