Regex: C# extract text within double quotes

后端 未结 7 1058
悲哀的现实
悲哀的现实 2020-11-27 17:03

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

7条回答
  •  孤独总比滥情好
    2020-11-27 17:34

    I combine Regex and Trim:

    const string searchString = "This is a \"search text\" and \"another text\" and not \"this text";
    var collection = Regex.Matches(searchString, "\\\"(.*?)\\\"");
    foreach (var item in collection)
    {
        Console.WriteLine(item.ToString().Trim('"'));
    }
    

    Result:

    search text
    another text
    

提交回复
热议问题