Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex to remove text between tags in Notepad++

I have a 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>

removing everything inside the tag.

like image 268
sivi Avatar asked Sep 01 '12 07:09

sivi


People also ask

Does Notepad ++ have regex?

Using Regex to find and replace text in Notepad++ In all examples, use select Find and Replace (Ctrl + H) to replace all the matches with the desired string or (no string). And also ensure the 'Regular expression' radio button is set.


1 Answers

Search for

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

and replace all with

<wp:post_name></wp:post_name>

This assumes that tags can't be nested (which makes the regex quite safe to use). If other tags may be present, then you need to search for

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

instead (same replace string). However, this probably only works in the latest versions of Notepad++ which brought a major regex engine overhaul, and it's a bit riskier because it will mess up your file if nested <wp:post_name> tags can occur.

like image 168
Tim Pietzcker Avatar answered Sep 27 '22 20:09

Tim Pietzcker