C#中利用正则表达式获取字符串中双引号包含的内容
代码:
using System.Text.RegularExpressions; namespace GetData { internal class Program { private static void Main(string[] args) { var lines = File.ReadAllLines("data.txt"); Regex re = new Regex("(?<=\").*?(?=\")", RegexOptions.None); var myList = new List<string>(); foreach (var line in lines) { MatchCollection mc = re.Matches(line); foreach (Match m in mc) { myList.Add(m.Value); Console.WriteLine(m.Value); } } File.WriteAllLines("result.txt", myList.ToArray()); Console.WriteLine("---------------------"); Console.ReadKey(); } } }