The following JavaScript outputs nothing (not even “false”), and indeed stops any other JavaScript on the page from running:
var pattern = new RegExp(/[_-%]/);
document.write(pattern.test("foo"));
What is it about this regular expression that does this? If any one of the three characters (_, -, or %) is removed, everything works normally. And if the order of the three characters is changed at all, everything works normally.
A hyphen in a [ ] block is used for ranges. So _ to % is invalid.
You can escape it:
or move to the start:
or to the end:
Since regex knows that a hyphen at the start (or end, thanks BrunoLM!) means a literal hyphen and not a range.