So I have a bunch of regexes and I try to see if they match with another string using this If statement:
if (samplestring.match(regex1)) {
console.log("regex1");
} else if (samplestring.match(regex2)) {
console.log("regex2");
} else if (samplestring.match(regex3)) {
console.log("regex3");
}
But as soon as I need to use more regexes this gets quite ugly so I want to use a switch case statement like this:
switch(samplestring) {
case samplestring.match(regex1): console.log("regex1");
case samplestring.match(regex2): console.log("regex2");
case samplestring.match(regex3): console.log("regex3");
}
The problem is it doesn't work like I did it in the example above. Any Ideas on how it could work like that?
break
.break
keyword.