C# Regular Expressions, string between single quotes

前端 未结 4 1962
时光取名叫无心
时光取名叫无心 2020-11-27 21:24
string val = \"name=\'40474740-1e40-47ce-aeba-ebd1eb1630c0\'\";

i want to get the text between \' quotes using Regular Expressions.

4条回答
  •  野性不改
    2020-11-27 21:59

    You could use positive lookahead and lookbehind also,

    string val = "name='40474740-1e40-47ce-aeba-ebd1eb1630c0'";
    
    Match match = Regex.Match(val, @"(?<=')[^']*(?=')");
    if (match.Success)
    {
        string yourValue = match.Groups[0].Value;
        Console.WriteLine(yourValue);
    }
    

提交回复
热议问题