正则表达式删除记事本++中标签之间的文本 [英] Regex to remove text between tags in Notepad++
本文介绍了正则表达式删除记事本++中标签之间的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个这样的代码
<wp:post_name>artifical-sweeteners-ruin-your-health</wp:post_name>
我想改成
<wp:post_name></wp:post_name>
删除标签内的所有内容.
removing everything inside the tag.
推荐答案
搜索
<wp:post_name>[^<>]+</wp:post_name>
并全部替换为
<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>
代替(相同的替换字符串).但是,这可能只适用于 Notepad++ 的最新版本,它带来了主要的正则表达式引擎大修,而且风险更大,因为如果嵌套 <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.
这篇关于正则表达式删除记事本++中标签之间的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文