-1

I have the following regex pattern: (?:http.?:\/\/)

This matches the protocol component from a web url, I want a regex to do the opposit, to match everything except the protocol, so far my every attempt has not worked at all.

Becuase ultimatly what I want to do is check if two urls are the same reguardless of protocol, so I can do:

if url_1[regex] == url_2[regex]
Thermatix
  • 2,757
  • 21
  • 51

3 Answers3

2

This should do it:

/.*?\/\/(.*)/
Chris Lear
  • 6,592
  • 1
  • 18
  • 26
  • Is there any way to do this without a capture group? `(?!.*\/\/).*` almost works, but it still matchs the last `/`, ok, doing this: `(?!.*\/\/)\w.*` works, problem soved. – Thermatix Jul 08 '16 at 12:25
0

You can use this regex to always capture the part after optional http:// or https:// at the start:

/^(?:[^:]+:\/\/)?(.+)$/

RegEx Demo

anubhava
  • 761,203
  • 64
  • 569
  • 643
0

Use this and take the second group $2

/^(?:[^:]*:\/\/)?(.*?)$/
Wilmer
  • 138
  • 1
  • 8