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 :-
- % (Percentage)
- " (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