Regex: C# extract text within double quotes

Try this regex:

\"[^\"]*\"

or

\".*?\"

explain :

[^ character_group ]

Negation: Matches any single character that is not in character_group.

*?

Matches the previous element zero or more times, but as few times as possible.

and a sample code:

foreach(Match match in Regex.Matches(inputString, "\"([^\"]*)\""))
    Console.WriteLine(match.ToString());

//or in LINQ
var result = from Match match in Regex.Matches(line, "\"([^\"]*)\"") 
             select match.ToString();

Leave a Comment