C# Regular Expressions, string between single quotes

前端 未结 4 1924
时光取名叫无心
时光取名叫无心 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:34

    You are looking to match GUID's in a string using a regular expression.

    This is what you want, I suspect!

    public static Regex regex = new Regex(
      "(\\{{0,1}([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-"+
      "([0-9a-fA-F]){4}-([0-9a-fA-F]){12}\\}{0,1})",RegexOptions.CultureInvariant|RegexOptions.Compiled);
    
    Match m = regex.Match(lineData);
    if (m.Succes)
    {
    ...
    }
    

提交回复
热议问题