简体   繁体   中英

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. Deleting everything from print and end will also work

You could use

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

Explanation

  • \{ Match {
  • print\h+ match print and 1+ horizontal whitespace chars
  • \K Forget wat is matched so far
  • [^{}]*\R Match 0+ times any char except { or } and a newline
  • (?=}end) Positive lookahead, assert what is on the right is }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]+?(?=})
Replace with: nothing

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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