Website RegEx pattern

Hi,

How can I make a reguluar expression pattern which accepts websites only but includes all type of website domains, e…g [dot]online, [dot]co, [dot]com, http, https, etc…

I tried below but it’s not working with many domains

/^((http[s]?|ftp):\/)?\/?([^:\/\s]+)((\/\w+)*\/)([\w\-\.]+[^#?\s]+)(.*)?(#[\w\-]+)?$/

Thanks,

Jassim

Try this: (The following regex is written for a text editor, not JS.)

\b(https?|ftp|file)://[-A-Z0-9+&@#/%?=~_|$!:,.;]*[A-Z0-9+&@#/%=~_|$]

Samples: matches are yellow, not matched are not colored.

IF you cannot work with this, then supply a full range of samples showing exactly what you need to capture and what to do not wish to capture.

[off topic]
My knowledge of regex is severely limited and if Php was available I would use:

'sitepoint'===$_SERVER['SERVER_NAME']

What am I missing?
[/Off topic]

Edit:
Replaced incorrect session with server.

Is this for client side validation of an input? You could just use type="url" in that case.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.