简体   繁体   中英

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 "?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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