How can I create a Regular expression to match the following characters:
A-Z a-z 0-9 " - ? . ', !
… as well as new lines and spaces
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This will match any single one of those characters:
There’s a good chance you want something like:
Or possibly a bit simpler will meet your needs:
Remembering that if this is inside a string, you will need to escape either the
"or'in that (either by doubling up, or by prefixing with a backslash).Also note that the
-is last so that it is not treated as a range inside the character class. (Can also be placed first, or prefixed with backslash to prevent that).The
\wwill match a “word” character, which is almost always[A-Za-z0-9_].The
\swill match a whitespace character, (i.e. space,tab,newline,carriage return).But really you need to give more context to what you’re trying to do so people can suggest more fitting solutions.