I want to extract the base name from a image URL in Javascript. Would somebody care to give me a a hand on the Regex?
The rule would be:
return everything right of the last /
left of the last .
www.domain.com/images/image.hires.jpg
if no .
is found, return the full base name
www.domain.com/images/image_hi_res
I have a clumsy /\/[^.]+\.[^.]+$/
but don't know how to make the /
and the .
optional and how to seek for the last .
only.
Cheers folks for all the great input, as always. I chose the one Regex that worked for me out of the box.
To find the base URL of your website, go to the site's front page. What you see in the address bar on your site's front page is the base URL of your website.
The getHost() method of URL class returns the hostname of the URL. This method will return the IPv6 address enclosed in square brackets ('['and']').
HTMLInputElement. checkValidity() method is used to check if a string in <input> element's value attribute is URL . The checkvalidity() method returns true if the value is a proper URL and false if the input is not a proper URL.
Yet another solution:
url.replace(/^.*\/|\.[^.]*$/g, '')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With