简体   繁体   English

C#等同于preg_match_all?

[英]What is C# equivalent of preg_match_all?

The theme is i opened a file and get all it's data into string and i am matching this string with the regex returning none. 主题是我打开了一个文件,并将所有数据放入字符串中,并且此字符串与不返回任何正则表达式的字符串进行了匹配。 But the same regex in PHP is returning values for the same text using preg_match_all. 但是,PHP中相同的正则表达式使用preg_match_all返回相同文本的值。 Anyone having a idea? 有人有主意吗?

The method in .NET that's closest to preg_match_all() is the static Regex.Matches(String,String) call, or the equivalent Matches method on a compiled regular expression. .NET中最接近preg_match_all()是静态Regex.Matches(String,String)调用,或已编译正则表达式上的等效Matches方法。 It returns a MatchCollection that you can use to count the matches and to loop over each one. 它返回一个MatchCollection ,您可以用它来计数匹配项并遍历每个匹配项。

Can you provide some short, self-contained code to show what's not working? 您可以提供一些简短的自包含代码来显示什么不起作用吗?

您可以使用C#中的Regex.Matches方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM