Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
87
rated 0 times [  91] [ 4]  / answers: 1 / hits: 48638  / 12 Years ago, thu, november 22, 2012, 12:00:00

Capture the domain till the ending characters $, ?, /, :. I need a regex that captures example.com in all of these.


example.com:3000
example.com?pass=gas
example.com/
example.com

More From » node.js

 Answers
52

I reccomend using the new URL class that is now included in most browsers.




var urls = [
'http://example.com:3000',
'http://example.com?pass=gas',
'http://example.com/',
'http://example.com'
];

urls.forEach(url => {
const u = new URL(url)
console.log(u.hostname)
})




[#81866] Tuesday, November 20, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
devlin

Total Points: 474
Total Questions: 113
Total Answers: 100

Location: Sweden
Member since Fri, Apr 16, 2021
3 Years ago
devlin questions
Tue, Apr 27, 21, 00:00, 3 Years ago
Sat, Oct 31, 20, 00:00, 4 Years ago
Fri, Aug 28, 20, 00:00, 4 Years ago
;