正则提取邮箱,邮箱正则表达式获取邮箱类型

        static void Main(string[] args)
        {
            string str = File.ReadAllText("1.txt", Encoding.Default);
            MatchCollection mc = Regex.Matches(str, @"([-a-zA-Z_0-9.]+)@([-a-zA-Z0-9_]+(\.[a-zA-Z]+)+)");
            foreach (Match m in mc)
            {
                Console.WriteLine(m.Value);
                Console.WriteLine(m.Groups[2].Value);//([-a-zA-Z_0-9.]+)@([-a-zA-Z0-9_]+(\.[a-zA-Z]+)+)")这是第一组,([-a-zA-Z_0-9.]+)第二组([-a-zA-Z0-9_]+(\.[a-zA-Z]+)+)")第三组(\.[a-zA-Z]+)+)第四组
                Console.WriteLine("=========");
            }
            Console.WriteLine(mc.Count);
            Console.ReadKey();
        }

评论