Chelovek
Chelovek

Reputation: 159

Remove part of the lines except few characters?

I am looking for the way to delete part of the line, but there is some text static, which doesn`t change. Example:

http://example1.com/index.php?static=bread&dasd
http://example2.com/?static=oil&gas&check

So I want to remove &dasd from the first line and &gas&check the from second line. I have thousands of lines of this and found some difficulties, as the domain and string after static= can contain different number of characters. In addition, different number of characters can come before the & sign.

Upvotes: 0

Views: 46

Answers (2)

enrico.bacis
enrico.bacis

Reputation: 31544

Just find using the regex:

&.*

and replace with blank.

Upvotes: 0

falsetru
falsetru

Reputation: 369494

You can use capturing group and backreference.

Find what:

(static=[^&]*).*

Replace with:

\1

Upvotes: 2

Related Questions