C# Regex for Guid

后端 未结 6 1242
情歌与酒
情歌与酒 2020-11-27 03:08

I need to parse through a string and add single quotes around each Guid value. I was thinking I could use a Regex to do this but I\'m not exactly a Regex guru.

Is

6条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-27 03:37

    You can easily auto-generate the C# code using: http://regexhero.net/tester/.

    Its free.

    Here is how I did it:

    enter image description here

    The website then auto-generates the .NET code:

    string strRegex = @"\b[A-F0-9]{8}(?:-[A-F0-9]{4}){3}-[A-F0-9]{12}\b";
    Regex myRegex = new Regex(strRegex, RegexOptions.None);
    string strTargetString = @"     {CD73FAD2-E226-4715-B6FA-14EDF0764162}.Debug|x64.ActiveCfg =         Debug|x64";
    string strReplace = @"""$0""";
    
    return myRegex.Replace(strTargetString, strReplace);
    

提交回复
热议问题