Regex: C# extract text within double quotes

c#, regex

Solution

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

Problem

I want to extract only those words within double quotes. So, if the content is: Would "you" like to have responses to your "questions" sent to you via email? The answer must be - you - questions

Original source