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

前端之家收集整理的这篇文章主要介绍了C#正则表达式,单引号之间的字符串前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
string val = "name='40474740-1e40-47ce-aeba-ebd1eb1630c0'";

我想使用正则表达式的引号之间的文本.

可以吗

解决方法

这样的事情应该做到这一点:
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
原文链接:https://www.f2er.com/csharp/97192.html

猜你在找的C#相关文章