Reputation: 1536
there I apply two regular expression to javascript string:
url.replace(/(^https?\:\/\/)?(www\.)?/i, '').replace(/\/$/, '')
how can I combine them into one replace
function?
Upvotes: 1
Views: 119
Reputation: 20747
Since the replacement is the same, you can use alternation to match/replace "this" or "that":
let url = 'http://www.example.com/';
console.log(url.replace(/^(?:https?\:\/\/)?(?:www\.)?|\/$/gi, ''));
Upvotes: 1