simple regex: multiple dots(.)
I am trying to delete everything after the .com, .etc, in a URL; to make it more meaningful
so
sub.domain.com/324fr9?=awerf?=awrf
turns to
sub.domain.com/
except the same regex doesn't work for
noSubDomain.com/crap?=yes123456789timesOver
because it only has one dot, not two!
Here's my regex(javascript):
/.*:\/\开发者_如何学编程/.*\..*\.com/g
If you are segmenting the URL and you want to do it in perl CPAN's URI module might be a better option. $uri->host
is what you want, but you can do many other things using URI module.
Javascript has the window.location
object which is better to use for getting URL information - http://www.w3schools.com/jsref/obj_location.asp
Else, you could just design your regex to delete everything after the /
instead.
url = url.replace(/\/.*/g, "/");
/.*:\/\/(.*\.)?.*\.com/g
Here's the part that matters: (.*\.)?
The question mark says that everything in that group is optional.
精彩评论