admin管理员组

文章数量:1326447

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?

Share Improve this question asked Feb 16, 2016 at 8:13 Max KoretskyiMax Koretskyi 106k67 gold badges353 silver badges515 bronze badges 1
  • You can refer to this link: stackoverflow./questions/1127739/… – Calyfs0 Commented Feb 16, 2016 at 8:18
Add a ment  | 

3 Answers 3

Reset to default 5

You 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]*$/

本文标签: javascriptmatch ascii characters except few charactersStack Overflow