Reputation: 1844
I need to check whether my string got only
alphabets of the form
or of the form - 'Text'
or of the form - "Text"
How to frame a regex for that? Currently what im using is provided below and that seems not working. Please help me modify this. Thanks in advance.
Regex isString = new Regex("[^a-zA-Z]|[^']|[^\"]");
Upvotes: 0
Views: 2855
Reputation: 15503
Regex isString = new Regex("^['][a-zA-Z]*[']|[\"][a-zA-Z]*[\"]|[a-zA-Z]*$");
Upvotes: 1
Reputation: 21366
Regex isString = new Regex("(['\"]?)[a-zA-Z]+\\1$");
this will match "text"
, 'text'
and not with 'text"
Upvotes: 2