GLP GLP - 2 months ago 15
ASP.NET (C#) Question

What is the regular expression for "No quotes in a string"?

I am trying to write a regular expression that doesn't allow single or double quotes in a string (could be single line or multiline string). Based on my last question, I wrote like this

^(?:(?!"|').)*$
, but it is not working. Really appreciate if anybody could help me out here.

Answer

Just use a character class that excludes quotes:

^[^'"]*$

(Within the [] character class specifier, the ^ prefix inverts the specification, so [^'"] means any character that isn't a ' or ".)