Regex to remove text between tags in Notepad++

限于喜欢 提交于 2019-12-31 09:04:34

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/12225729/regex-to-remove-text-between-tags-in-notepad

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!