Home > Back-end >  Regular Expresion for all ASCII charcters but not % and " (double quotes)
Regular Expresion for all ASCII charcters but not % and " (double quotes)

Time:08-04

I am looking for a Regular expression to validate input string so that it contains ASCII characters from 32 to 126. I am currently using [ -~] and this Regular is working as expected.

I also need to check that the input String must not contain below characters :-

  1. % (Percentage)
  2. " (Double Quotes)

CodePudding user response:

[ !#$&-~] should do the trick.

Since " is 34 and % is 37 it's simpler to just list the early acceptable characters and use a range for the rest.

CodePudding user response:

To check if a string contains only ASCII characters and does not contain % and/or " you can use

^(?!<=["%])[ !#$&-~]*(?!=["%])$

You can check a demo here

  • Related