Shankar M G
Shankar M G

Reputation: 33

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

Upvotes: 0

Views: 1629

Answers (2)

Haji Rahmatullah
Haji Rahmatullah

Reputation: 430

I'm getting familiar day by day to Regex usage, so here I share my approach ....

Find what: next[\s\S]+?(?=})
Replace with: nothing

enter image description here

Upvotes: 1

The fourth bird
The fourth bird

Reputation: 163632

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.

enter image description here

Upvotes: 2

Related Questions