Виктор
Виктор

Reputation: 47

Why does regex match the symbol "m"

This regex matches the last "m" from the example input. How to avoid this matching?

Example: https://regex101.com/r/WZmdfH/2/

Tried Regex: [^:](\/\/) Tried Input: https://www.example.com//

I'm expecting that the regex finds all double slashes (//) except the first in https://.

I want to replace all // in urls like https://example.com/123/345//123//909 (except the first)

Upvotes: 1

Views: 133

Answers (1)

Nishant
Nishant

Reputation: 21914

You can use a negative lookbehind to achieve this:

(?<!:)(\/\/)

If you want to be more precise, you can include http(s) as well:

(?<!https:|http:)\/\/

See this Regex101 example.

Upvotes: 2

Related Questions