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?
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?
- You can refer to this link: stackoverflow./questions/1127739/… – Calyfs0 Commented Feb 16, 2016 at 8:18
3 Answers
Reset to default 5You can use negative lookahead for disallowed chars:
/^((?!['"])[\x00-\x7F])*$/
RegEx Demo
(?!['"])
is negative lookahead to disallow single/double quotes in your input.
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])*$/
The IMO by far simplest solution:
/^[\x00-\x21\x23-\x26\x28-\x7F]*$/