简体   繁体   English

正则表达式删除记事本++中标签之间的文本

[英]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.删除标签内的所有内容。

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.然而,这可能只适用于 Notepad++ 的最新版本,它带来了一个主要的正则表达式引擎大修,而且风险<wp:post_name>因为如果嵌套<wp:post_name>标签可以出现,它会弄乱你的文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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