0
    var message = "hello [[xxx]] bye [[ZZZ]]"

var result, re = /\[\[(.*?)\]\]/g;
while ((result = re.exec(message)) != null) {
    switch (result[1].toLowerCase()) {

        case "xxx":
            console.log("found xxx");
            break;

        case "zzz":
            console.log("found zzz");
            break;
    }
}

This is an example of the code im using, currently it will output

found xxx
found zzz

Is there a way to put multiple ways to "trigger" a case? such as

case "xxx", "aaa", "bbb":
            console.log("found 3xletters");
            break;

I've tried this ^^^ but only the last thing can trigger it, so in the above case xxx and aaa wont trigger, but bbb will

Cyan101
  • 19
  • 4
  • ahh my bad, it is indeed :3 i did a quick search but i fear i didn't know the proper "wording" so i didn't find anything – Cyan101 Feb 13 '16 at 06:36

1 Answers1

0

Yes, you can do this, but I would not recommend it if you have very many alternatives per case. In switch statements break ensures that the program exists the switch statement rather than continuing on to the following cases. So, if you want to check for multiple cases, you can simply leave break out of all but the last one, like so.

...

switch (result[1].toLowerCase()) {
  case "aaa":
  case "bbb":
  case "xxx":
      console.log("found aaa, bbb, or xxx");
      break;
  case "zzz":
      console.log("found zzz");
      break;
}
McMath
  • 6,862
  • 2
  • 28
  • 33