The regular expression /[^?-~]/ matches a character that is not in the range "?" (ascii value 63) through "~" (ascii value 126). The character "&" is ascii value 38, outside the range. So the regex matches it. Note that "a", "s", "d", and "f" are all inside the range, so they are not matched.