0

I am trying to replace long URLs with a new domain that just go to the root, but when I use the wildcard, it is replacing more than just the URL but code that is written after it

I tried adding what to search for after the wildcard, which would be a quote " but it doesnt seem to stop at the FIRST quote.

for example I was using find: site1.com/.*" replace:site2.com/shop

but it is giving me site1.com/2018/02/08/best-cannabis-strains-relieve-stress/" rel="canonical" /><meta property="og:locale" and keeps going. How do I make the wildcard string stop at the FIRST " and not keep going

Toto
  • 89,455
  • 62
  • 89
  • 125
mandude
  • 1
  • 1
  • Possible duplicate of [My regex is matching too much. How do I make it stop?](https://stackoverflow.com/questions/22444/my-regex-is-matching-too-much-how-do-i-make-it-stop) – Toto Apr 16 '19 at 18:03

2 Answers2

0

This should solve your problem: site1\.com\/[^"]*

[^"] means: anything but a quote.

If you want to learn more, you should look up regular expressions.

Ushyme
  • 140
  • 1
  • 8
  • Thanks I will try this. Can you explain this for a noob like me and maybe future finders? why do you put the .com in \ \ ? Also I want the search to stop at the first quote, because that is when the domain code ends, so I guess that means it will look UP TO that point then stop if I am understanding correctly? – mandude Apr 16 '19 at 03:22
0

It does not stop at first quote because * is a greedy quantifier. It means it will find as much as it is able to.

In order to make it lazy (that is, stop as soon as possible) you may add ? to the quantifier. That is: *?

So, given this string aaabaaab

This regexes will match:

^.*baaabaaab

^.*?baaab

NOTE:

The lazy modifier also works for other quantifiers like ?, + and {}

As commented on the other answer, another way to stop at the first quote with a greedy quantifier is not using ., but anything but quote character: [^"]*"

Julio
  • 5,208
  • 1
  • 13
  • 42
  • Thank you for dumbing it down for me this helped! It is interesting that there are multiple ways to accomplish the same thing, especially for something as small as a search and replace feature! – mandude Apr 16 '19 at 18:32