lk1234
lk1234

Reputation: 113

Regular expression for deleting string after a character

I have a file with about 1000 lines and want to delete eerything after a character on each line in notepad++. Example of format:

text=more text
text=more text
text=more text
text=more text
text=more text

I want to delete all text after the = on each line so the output would be:

text=
text=
text=
text=
text=

I have tried numerous expressions but cant seem to get it to work.I have tried:

Find what: =.*
Replace with:

and it doesn't work

Upvotes: 1

Views: 159

Answers (2)

vks
vks

Reputation: 67968

^.*?=\K.*

You can use \K over here.This way evrything upto = will be saved and rest deleted.See demo.Replace with empty string

https://regex101.com/r/fM9lY3/15

Upvotes: 0

vog
vog

Reputation: 25597

If you want to keep the "=", you have to put it into your replacement string:

Find what: =.*
Replace with: =

Otherwise, everything after the = including the = would be deleted.

As a side node, I prefer to explicitly use the end anchor $ in regular expressions:

Find what: =.*$
Replace with: =

(Although that is not strictly needed as the * operator is greedy by default.)

Upvotes: 1

Related Questions