Add first version of the function removeCharactersNotInPattern