I want to get the relative URL from an absolute URL in JavaScript using regex and the replace method.
I tried the following but it is not working:
va
const url = new URL('https://www.example.com/path/#anchor?query=value'); const rel = url.toString().substring(url.origin.length) console.log(rel) // Output: /path/#anchor?query=value