简体   繁体   English

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

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

How can I match comments in page source that start in symbols "//" but skip urls that also have "//" like " https://test.test.test/testing "?如何匹配页面源中以符号“//”开头的评论,但跳过也有“//”的网址,如“ https://test.test.test/testing ”?

My code right now is:我现在的代码是:

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);

add not present of ':' symbol and set multi line option添加不存在的 ':' 符号并设置多行选项

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

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

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

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