How to remove everything between two words in RegEx?

90 Views Asked by At

I want to remove everthing between .com/ to ?utm

How can I do that? I use Notepad++ and Kate.

https://www.forexample.com/cat.belt?utm2900&eav=AfbHJya2K7Mbg2mPWatN
https://www.forexample.com/cat.food?utm89748&eav=AfbHJya2K7Mbg2mPWatN
https://www.forexample.com/dog.necklace?utm25875&eav=AfbHJya2K7Mbg2mPWatN
https://www.forexample.com/dog.belt?utm25285&eav=AfbHJya2K7Mbg2mPWatN
https://www.forexample.com/dog.food?utm785844&eav=AfbHJya2K7Mbg2mPWatN

I tried to Google the solution, but nothing really works.

2

There are 2 best solutions below

1
On

try the pattern: (^.*?\.com\/)(?:.*?)(\?utm.*$)

substitution: $1$2

demo here: https://regex101.com/r/xChAme/2

0
On

In that case, you could use (?:^.*?\.com\/)(.*?)(?:\?utm.*$) with $1 matching "cat.belt", "cat.food" etc.

In fact, the only change in comparison to @akash 's answer is that you invert the capturing and non-capturing groups.