Match ascii characters except for a few characters

I have a regex that matches all ascii characters:

/^[\x00-\x7F]*$/

Now I need to exclude the following characters from this range: ', ". How to do it?

+4
source share
3 answers

You can use a negative result for forbidden characters:

/^((?!['"])[\x00-\x7F])*$/

RegEx Demo

(?!['"]) - negative lookahead to forbid single / double quotes in your input.

+2
source

You can exclude characters from the range by doing

/^(?![\.])[\x00-\x7F]*$/

prefix c (?![\.])to exclude .regular expressions from matching.

or in your script

/^(?!['"])[\x00-\x7F]*$/

Edit:

,

/^((?!['"])[\x00-\x7F])*$/
+2

IMO the easiest solution:

/^[\x00-\x21\x23-\x26\x28-\x7F]*$/
+1
source

Source: https://habr.com/ru/post/1628940/


All Articles