url regex without http://www
14,652
It would probably be a good idea to keep the www
's intact in order to preserve the sub-domain. A regex pattern like this:
^([a-zA-Z0-9]+(\.[a-zA-Z0-9]+)+.*)$
would match a URL that is not prefixed by a protocol (http://
,https://
,ftp://
,etc).
Related videos on Youtube
Comments
-
input almost 2 years
i need a url regex which validates the url string without
http://www.
orhttps://www.
any ideas?
-
Hinek almost 14 yearsgive an example of the string you have and the string you want to extract ... or do you want to validate if the string is an url but does not start with www.?
-
BC. almost 14 yearsIt seems clear to me. OP wants a url regex pattern that doesn't match "www.". @fusion Why not take an existing one and remove that match from the beginning of the pattern?
-
Lèse majesté almost 14 yearsHe could have also meant a regex that strips
http://www.
from a URL. Since he doesn't specify a use case and apparently spent less than 10 seconds writing the question, it's hard to tell. -
input almost 14 yearsapologies for not being clear. i want the regex to validate the url string but without
http://www.
it should only validategoogle.com
nothttp://www.google.com
-
Lunivore almost 14 yearsHi Fusion, do your URLs have ports, parameters, etc.?
-
Kevin Sedgley almost 14 yearsDo you want to be able to extract URLs from a string, like gmail chat does, without having to specify 'http://' or 'www.'? So for instance
boobi.es
would be turned to [boobi.es](boobi.es)? I forsee a lonnnnng regex. -
sigint almost 14 yearsWhat if a website requires the
www
subdomain to be valid? Ex.www.example.com/
serves a page, butexample.com/
404's. -
input almost 14 years@lunivore, no. @kevin, yes something like that.
-
input almost 14 years@sigint, i'm not removing
http://www.
. it'd be programmatically appended to the url which the user enters in the textbox. i don't want the user to enterhttp://www.
-
Quentin almost 14 yearsSo run your regular expression against "www." + what_the_user_enters. Hope you don't mind excluding https URIs.
-
-
input almost 14 yearsthank you! as i said i'm not removing the www. it would be appended to the url which the user enters in the textbox.
-
Joel Etherton almost 14 yearsThat regex would allow silliness like subdomain.realdomain.Hambone^&&#$@$%^&* which wouldn't qualify.
-
sigint almost 14 years@fusion What if
example.com
doesn't have awww
subdomain? You shouldn't blindly prepend thewww
's. @Joel Etherton You are correct, this regex pattern would be VERY liberal when dealing with (what should be) GET parameters. -
FOOM over 5 yearsalso doesn't allow hyphens