Uneccessary Regex vs. String functions
by Darth Vader
JavaScript
var testFin = /^(FIN\s*)(\w{4})/i;
var testInputArray = ["FIN4232", "fin4323", "fin 4323", "FIN 43435", "fIN4311", "Fin 39282", "Fin 2"];
for(index=0; index<testInputArray.length; index++) {
console.log("For index: ", index, " with value: ", testInputArray[index], " Pattern Match Result: ", testFin.test(testInputArray[index]), " with replacement: ", testInputArray[index].replace(testFin, "$2"));
}
for(index=0; index<testInputArray.length; index++) {
var input = testInputArray[index];
var match = input.toLowerCase().replace(" ", "").startsWith("fin");
console.log("For index: ", index, " with value: ", input, " Pattern Match Result: ", match, " with replacement: ", testInputArray[index].replace("\s|fin/i", ""));
}