regex needed to strip out domain name -
i need regexp strip out domain name part of url. example if had following url:
the bit i'd want regex match 'website-2000'
if explain each part of regex me understand great.
thanks
this 1 should work. there might faults it, none can think of right now. if want improve on it, feel free so.
/http:\/\/(?:www\.)?([a-z0-9\-]+)(?:\.[a-z\.]+[\/]?).*/i http:\/\/ matches "http://" part (?:www\.)? non-capturing group matches 0 or 1 "www." ([a-z0-9\-]+) capturing group matches character ranges a-z, 0-9 in addition hyphen. wanted extract. (?:\.[a-z\.]+[\/]?) non-capturing group matches tld part (i.e. ".com", ".co.uk", etc) in addition 0 or 1 "/" .* matches rest of url
Comments
Post a Comment