I'm trying to remove the whitespace from the beginning and the end of the input string, replace more than 1 space with just one space and remove all special characters. The snippet (attached herewith) works but I just wanted to ask if there is a way I can make this look slightly less uh... ugly? There must be a better way of writing this, right?
const filterInput = (vals) => {
console.log(vals.replace(/^(\s*)|(\s*)$/g, '').replace(/\s+/g, ' ').replace(/[^\w ]/g, ""));
};
filterInput(" squid*^%ward sponge((bob ")