Q: How to exclude letters? I'm using regular expressions in my code to check for a few letters/letter sequences.
This is my code:
<script>
function myFunction() {
    // var str = "wr"; true
    // var str = "wR"; true
    // var str = "au"; true
    // var str = "u";  true
    // var str = "a";  true
    var str = "r";    // Must be false.
    alert(/[wr|wR|au|u|a]/.test(str));

}
</script>


As shown in the code it returns true for wr, wR, au, and a. As for r, and R it must be false.
But if I give 'r' or 'R' it is returning true instead of false!
I'm not that good at Regular Expressions. Can any one help me with this?

A: A character class ([…]) will match any single instance of any character (or range of characters) that you place in side it. If you want to use alternations (|), they must be outside of a character class:
alert(/wr|wR|au|u|a/.test(str));

Also, you might want to put it in a group ((…)) and use start (^) and stop ($) anchors around your pattern, otherwise, it would happily match the a in war.
alert(/^(wr|wR|au|u|a)$/.test(str));

