given this set of letters
xx | af | an | bf | bn | cf | cn
how can I see if, given two characters, they match against one of the above?
I could easily hardcode the solution with a switch case, but I think regex is a more elegant solution.
You basically wrote the regex yourself:
xx|af|an|bf|bn|cf|cn
You wrote the regular expression yourself as stated previously, you could simplify it to...
var re = /xx|[abc][fn]/
Try this:
^(xx|af|an|bf|bn|cf|cn)$
xx => Correct
af => Correct
aff => Incorrect
kk => Incorrect
Live demo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With