C# Regular Expressions, string between single quotes

Something like this should do it:

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);
}

Explanation of the expression '([^']*):

 '    -> 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

Leave a Comment