正则表达单引号和双引号

时间:2013-05-29 03:47:48

标签: c# regex winforms

我只想知道单引号和双引号的正则表达式是什么,特别是这样的1:

openquote(startswith)+ word + closequote(endswith)

(singlequote)word(/singlequote) sample-> 'asdasdasdass'

(doublequote)word(/doublequote) sample-> "asdasdasdass"

在c#winforms / thanks。

---已更新:

替换此行中的正则表达式:

string hoveredWord = r.GetFragment("[a-zA-Z]").Text;

谢谢!

2 个答案:

答案 0 :(得分:3)

以下 RegEx 适用于单引号+部分文字+单引号 ('asdasdasdass')

Regex regexString = new Regex(@"'[^']*'");

以下 RegEx 适用于双引号+部分文字+双引号 (“asdasdasdass”)

Regex regexString = new Regex(@"""[^""]*""");

答案 1 :(得分:0)

正则表达式:

Former example : ^\'\w+\'
Later example : ^\"\w+\"

^ : match the beginning of the string
\' or \" : match the single quote or double quote
\w+ : match the alpha-numeric characters and underscore
相关问题