Hey!

I have a problem with C# regex. Can you please tell me how I can match anchor:

Atm I have it like this:

Regex.Match(pagecontent, @"<a (.*) href=" + url + "(.*)>(.*?)</a>");

but some how it doesnt want to work for

<a target="_blank" href="http://myurl.com">Title</a>

And I need to get "Title" where href is http://myurl.com

Please help me out.

Hmmm.. I tried this:

Match a = Regex.Match(PageContent, @"<a(.*)href='[" + replace + "]'(.*)>(.*)</a>");
anchor = a.Groups[2].Value;

But it looks that it's wrong.

Ok..

Match a = Regex.Match(PageContent, @"<a(.*)href=""(.*)trillhosting.com""(.*)>(.*)</a>");
anchor = a.Groups[4].Value;

This gives me some matches. I have 3 page contents. First is empty second one has "Home Page" for that "title" and second one has "Reliable Web Hosting"..

But somehow it shows me:
"Home Page" and then "vBulletin (tm)" but it should say "Reliable Web hosting"..

I'm afraid this is beyond my knowledge. I very rarely use regex so I don't know how to help any further. Sorry ^^

I fixed it :D

Match a = Regex.Match(PageContent, @"<a target=""_blank"" href=""http://trillhosting.com""(.*?)>(.*?)</a>");

But it doesn't work on every page because not every site has target="_blank" etc..
So I need a way how to have it like..

<a .. if exists other attributes ignore them .. href="myurl.com" .. if here's some tags too ignore them .. >(.*)</a>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.