Match regex with no consecutive characters

I have this regex (link to the with this pattern and examples)

const reg = /^(?:http(s)?://)[w.-]+(?:.[w.-]+)+[/]?[w-._~:?#[]@!$&'()*+,;=./]+$/gm

And it matches this urls

And not matches this asdasd

Where can I add exception so it will not match urls like this with consecutive / character?

I’ve tried to add /{1} and (?!./) but it’s not working.


You can amend your regex to


See the regex demo.

That is, replace [/]?[w-._~:?#[]@!$&'()*+,;=./]+ with (?:/[w.~:?#[]@!$&'()*+,;=.-]+)*/?. This pattern part will make sure the / char is always separated from another / with at least one char.

Also consider replacing (?:/[w.~:?#[]@!$&'()*+,;=.-]+)* with (?:/[^/]+)* if you do not care about what chars you can have in between /s, [^/] matches any char but /.