const matchLocation = (href) => {
if(typeof href !== 'string') {
throw new TypeError('Not string.');
}
const { hostname, port, pathname } = location;
const _hostname = hostname.replace(/([\/\.\*\(\)])/g, '\\$1');
const _pathname = pathname.replace(/\//g, '\\\/');
const _r = new RegExp(
`^(http|https):\\\/\\\/${ _hostname }(:(${ port })?)?${ _pathname }(\\\?.+)?(#.*)?$`
);
return href.match(_r);
};
const el = document.getElementsByTagName('a')[0];
matchLocation(el.href);
パラメータとハッシュは無視するようにしています。