+ -
当前位置:首页 → 问答吧 → 求一个c#正则表达式

求一个c#正则表达式

时间:2011-12-20

来源:互联网

哈哈哈[怒]sdfsdf[怒]斯蒂芬金水电开发[怒][偷笑][偷笑][偷笑]

提取出 [怒] 这些表情。

用c#怎么提取

作者: jiazhengjing   发布时间: 2011-12-20

C# code

            string input = "哈哈哈[怒]sdfsdf[怒]斯蒂芬金水电开发[怒][偷笑][偷笑][偷笑]提取[怒] 这些表情";
            Regex reg = new Regex(@"\[[^\]]+]");
            foreach(Match m in reg.Matches(input))
                Console.WriteLine(m.Value);

作者: pmars   发布时间: 2011-12-20

C# code
            string s = "哈哈哈[怒]sdfsdf[怒]斯蒂芬金水电开发[怒][偷笑][偷笑][偷笑]提取[怒] 这些表情";
            MatchCollection matches = Regex.Matches(s, @"(?<=\[).+?(?=\])");
            foreach (Match match in matches)
                Console.WriteLine(match.Value);
            Console.ReadKey();

输出:



偷笑
偷笑
偷笑

作者: dalmeeme   发布时间: 2011-12-20

相关阅读 更多