简体   繁体   English

如何删除记事本++中两个模式之间的所有行?

[英]How to remove all the lines between two patterns in notepad++?

I'm trying to replace the below text我正在尝试替换以下文本

"{print next
error
incorrect
err
}end"

to

"{print }end"

any I'm using (\{print)(.*?)(\}end) but not working.任何我正在使用(\{print)(.*?)(\}end)但不工作。 Deleting everything from print and end will also workprintend中删除所有内容也可以

You could use你可以使用

\{print\h+\K[^{}]*\R(?=}end)

Explanation解释

  • \{ Match { \{匹配{
  • print\h+ match print and 1+ horizontal whitespace chars print\h+匹配打印和 1+ 个水平空白字符
  • \K Forget wat is matched so far \K忘记 wat 到目前为止是匹配的
  • [^{}]*\R Match 0+ times any char except { or } and a newline [^{}]*\R匹配除{}和换行符以外的任何字符 0+ 次
  • (?=}end) Positive lookahead, assert what is on the right is }end (?=}end)正向前瞻,断言右边是}end

Regex demo正则表达式演示

In the replacement use an empty string.在替换中使用空字符串。

在此处输入图像描述

I'm getting familiar day by day to Regex usage, so here I share my approach....我越来越熟悉正则表达式的使用,所以在这里我分享我的方法....

Find what: next[\s\S]+?(?=})查找内容: next[\s\S]+?(?=})
Replace with: nothing替换为: nothing

在此处输入图像描述

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

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