Replaced switch statement with for loop and array of functions with regex logic