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


It works, but I'm not sure if there is a better way to go about it. I have some more codes to add as well so it will get longer. This RegEx will be used in Node as part of a JSON Schema for validation.

For validation they offer
pattern
that takes a RegEx.

Answer
var test = "ABC";
words = ["ADF", "ADP", ...]
if (words.includes(test)){
  return true;
}

Doing this with a regex makes no sense.