Replace switch case statement with if else aided by regex usage