Reputation: 33
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
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
Upvotes: 1
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
In the replacement use an empty string.
Upvotes: 2