Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Regex.Matches c# double quotes
- 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)
- }
- MatchCollection col = Regex.Matches(keywords, "\"(.*?)\"");
- string pattern = @"""([^""]|"""")*""";
- // or (same thing):
- string pattern = ""(^"|"")*"";
- "(^"|"")*"
- "(.*?)"
- "([^"]*)"
- var pattern = ""(.*?)"";
- var pattern = ""([^"]*)"";
- [Test]
- public void Test()
- {
- string input = "peace "this world" would be 'and then' some";
- MatchCollection matches = Regex.Matches(input, @"(?<=(['""])).*?(?=1)");
- Assert.AreEqual("this world", matches[0].Value);
- Assert.AreEqual("and then", matches[1].Value);
- }
Advertisement
Add Comment
Please, Sign In to add comment