一尘不染

C#正则表达式,单引号之间的字符串

c#

string val = "name='40474740-1e40-47ce-aeba-ebd1eb1630c0'";

我想'使用正则表达式获取引号之间的文本。

谁能


阅读 527

收藏
2020-05-19

共1个答案

一尘不染

这样的事情应该做到:

string val = "name='40474740-1e40-47ce-aeba-ebd1eb1630c0'";

Match match = Regex.Match(val, @"'([^']*)");
if (match.Success)
{
    string yourValue = match.Groups[1].Value;
    Console.WriteLine(yourValue);
}

表达式说明'([^']*)

 '    -> find a single quotation mark
 (    -> start a matching group
 [^'] -> match any character that is not a single quotation mark
 *    -> ...zero or more times
 )    -> end the matching group
2020-05-19