加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-15 17:59:45 所属栏目:百科 来源:网络整理
导读:string val = "name='40474740-1e40-47ce-aeba-ebd1eb1630c0'"; 我想使用正则表达式的引号之间的文本. 可以吗 解决方法 这样的事情应该做到这一点: string val = "name='40474740-1e40-47ce-aeba-ebd1eb1630c0'";Match match = Regex.Match(val,@"'([^']*)"
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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读