简体   繁体   中英

Regular Expression to check a string with special characters

I need to check whether my string got only

alphabets of the form

  • Text

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]|[^']|[^\"]");
Regex isString = new Regex("(['\"]?)[a-zA-Z]+\\1$");

这将匹配"text"'text'而不是'text"

Regex isString = new Regex("^['][a-zA-Z]*[']|[\"][a-zA-Z]*[\"]|[a-zA-Z]*$");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM