Reputation: 105449
I have a regexp that matches all ascii characters:
/^[\x00-\x7F]*$/
Now I need to exclude from this range the following characters: '
, "
. How do I do that?
Upvotes: 6
Views: 3953
Reputation: 522016
The IMO by far simplest solution:
/^[\x00-\x21\x23-\x26\x28-\x7F]*$/
Upvotes: 1
Reputation: 68393
You can exclude characters from a range by doing
/^(?![\.])[\x00-\x7F]*$/
prefixed it with (?![\.])
to exlude .
from the regex match.
or in your scenario
/^(?!['"])[\x00-\x7F]*$/
Edit:
wrap the regex in braces to match it multiple times
/^((?!['"])[\x00-\x7F])*$/
Upvotes: 3
Reputation: 784988
You can use negative lookahead for disallowed chars:
/^((?!['"])[\x00-\x7F])*$/
(?!['"])
is negative lookahead to disallow single/double quotes in your input.
Upvotes: 5