I've got a function that will display urls visited by users e.g. https://stackoverflow.com/questions/78/of/103/uk/ask
I want to use a regex expression with javascript to capture a specific parameter of the url and replace it with placeholder text. Taking the example above;
When https://stackoverflow.com/questions/7845w98439/uk/ask is matched, replace the '/78/of/103/uk/' part with '/task/of/total/country/'. The code below I have doesn't seem to work. Can someone show me where I'm going wrong?
JS:
const url_change = [
{expression: '/^/78/of/103/uk//i', value: '/task/of/total/country/'}
];
const urlParam = url_change.reduce(function(result, item) {
return element.classList.contains(item.expression) ? item.value : result;
}, '');
return urlParam(
toChange ? toChange.value : getElementText(element)
);
/^\/bla\/bleh etc