79333595

Date: 2025-01-06 15:57:25
Score: 0.5
Natty:
Report link

Use the native URL constructor

Don't use a regular expression here; there is no need, and it opens up the possibility of making mistakes. Use javascript's native URL constructor instead:

let url = new URL('https://stackoverflow.com/questions/7000995/jquery-removing-part-of-string-after-and-removing-too/7001040#7001040');
let hostname = url.hostname;
console.log(hostname); // stackoverflow.com

https://developer.mozilla.org/en-US/docs/Web/API/URL/URL

Reasons:
  • Blacklisted phrase (1): stackoverflow
  • Has code block (-0.5):
Posted by: tklodd