如何匹配评论但不是网址? c#regex

时间:2017-01-16 11:16:23

标签: c# regex comments

如何匹配以符号开头的页面源中的注释" //"但跳过也有" //"喜欢" https://test.test.test/testing"?

我现在的代码是:

Regex regex = new Regex(@"\/\/(.*?$)", RegexOptions.Multiline);
MatchCollection matchCollection1 = regex.Matches(pageSource);
string allMatches = string.Join(";", from Match match1 in matchCollection1 select match1.Groups[1].Value);

1 个答案:

答案 0 :(得分:1)

添加不存在':'符号并设置多行选项

[^:]\/\/(.*?$)/gm

https://regex101.com/r/Z8zz0n/2