Regex.Entspricht, c# double quotes

Ich habe diesen code unten das funktioniert für einfache Anführungszeichen.
es findet alle Wörter, die zwischen den einfachen Anführungszeichen.
aber wie würde ich ändern, die regex zu arbeiten, die mit doppelten Anführungszeichen?

keywords kommt aus einem Formular-post -

so

keywords = 'peace "this world" would be "and then" some'


    //Match all quoted fields
    MatchCollection col = Regex.Matches(keywords, @"'(.*?)'");

    //Copy groups to a string[] array
    string[] fields = new string[col.Count];
    for (int i = 0; i < fields.Length; i++)
    {
        fields[i] = col[i].Groups[1].Value; //(Index 1 is the first group)
    }//Match all quoted fields
    MatchCollection col = Regex.Matches(keywords, @"'(.*?)'");

    //Copy groups to a string[] array
    string[] fields = new string[col.Count];
    for (int i = 0; i < fields.Length; i++)
    {
        fields[i] = col[i].Groups[1].Value; //(Index 1 is the first group)
    }
  • Würde es nicht funktionieren, setzen die Anführungszeichen in den string? @-strings mit "" anstatt \" für Anführungszeichen. @"""(.*?)"""
InformationsquelleAutor user713813 | 2012-02-03
Schreibe einen Kommentar