One issue with the way that this library is implemented is that every regex is being re-initialized every time the function is run. A simple optimization would be to assign every regex to a variable and move it to the outer scope.