简体   繁体   English

正则表达式检查带有特殊字符的字符串

[英]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]*$");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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