-4

i want to check if any link contains underscore or not. i want to count how many hrefs contaning _

 MatchCollection links = Regex.Matches(html, "(<a.*?>.*?</a>)", RegexOptions.IgnoreCase | RegexOptions.Multiline);
 lbllinks.Text = "links .Count.ToString() + " links on this website ";

if string contains like <a id="HyperLink1" href="http://www.sample_1.com">HyperLink</a>

output - 1 underscore link

Krishna Mohan
  • 175
  • 1
  • 6
  • 14

1 Answers1

-2

i dont see whts the problem if some asking to solve one particular problem with regex.

give the suggestion to use the parser is different thing but down vote. i dont know why..

well u can try the below

https://regex101.com/r/gF7bE8/1

<a.*href\s{0,}=\s{0,}".*_.*".*>(.*)<\/a>

if any match found mean html contains the '_' in href of a. else does not.

Deepak Sharma
  • 4,124
  • 1
  • 14
  • 31
  • 1
    Maybe because it's a [problem](http://stackoverflow.com/a/1732454/2729609) to do that. Btw. Your regex doesn't work. Your own sample matches more than the requested link. On the other hand it doesn't work: [see here](http://goo.gl/Z5ShaV) There is no link containing underscores but your regex matches. – Sebastian Schumann Nov 08 '15 at 20:27
  • @Verarind oh i see.. hmm right. thanks to correct me.. and let me know my mistake .. !! – Deepak Sharma Nov 08 '15 at 20:36