繁体   English   中英

如何匹配评论而不匹配url? c#正则表达式

[英]How to match comments but not url? c# regex

如何匹配页面源中以符号“//”开头的评论,但跳过也有“//”的网址,如“ 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);

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

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

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

暂无
暂无

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

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