I am trying to find a string for words in single quotes, but only if these single quotes are not in parentheses.
Example line:
something, 'foo', something ('bar')
So, for this example, I would like to combine foo, but not bar.
After searching for examples of regular expressions, I can match in single quotes (see the code snippet below), but I'm not sure how to exclude matches in the context described earlier.
string line = "something, 'foo', something ('bar')";
Match name = Regex.Match(line, @"'([^']*)");
if (name.Success)
{
string matchedName = name.Groups[1].Value;
Console.WriteLine(matchedName);
}
source
share