Regular expression to remove text between tags in Notepad ++

I have code like this

<wp:post_name>artifical-sweeteners-ruin-your-health</wp:post_name> 

I want to change it to

 <wp:post_name></wp:post_name> 

removal of everything inside the tag.

+7
source share
1 answer

Search

 <wp:post_name>[^<>]+</wp:post_name> 

and replace everything with

 <wp:post_name></wp:post_name> 

This suggests that tags cannot be nested (which makes the regex completely safe to use). If other tags may be present, you need to search

 (?i)<wp:post_name>.*?</wp:post_name> 

instead (same replacement string). However, this probably only works in the latest versions of Notepad ++, which have led to a serious regex engine revision, and this is a bit more dangerous because it will corrupt your file if <wp:post_name> tags can occur.

+16
source

All Articles