Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have a tring same as :
...[down]<a title="Download: Click Here" href="http://www.domain.com/T60B8JK2WT/" target="_blank"><strong> KungFu Panda - Legends of Awesomeness (2011)(1 - 22)</strong></a> <a title="Download: Click Here" href="http://www.domain.com/5FBLQYBQTV/" target="_blank"><strong> KungFu Panda - Legends of Awesomeness (2011) </strong></a>[/down]...

How i can find [down][/down] tag in string & get all href attribute & text of each link in [down][/down] tag and put it in a data table, with each row of table is title & url field? Thanks & sorry for my english.
Posted
Updated 26-Jul-12 0:21am
v2

1 solution

Try something like this:
\[down](<a[^<]+href="(?<href>[^"]+)"[^<]*<strong>(?<text>[^<]*)</strong></a>\s*)+\[/down]
 
Share this answer
 
Comments
NgocThanh_89 26-Jul-12 6:40am    
@sjelen, thanks for your answer, i did get content with [down][/down] tag, how i can get text & href of each "a" tag? Thanks
sjelen 26-Jul-12 7:04am    
href and text are "named groups" here. If you have:
Match m = regex.Match(inputText);
then (using you input example):
m.Groups["href"].Captures[0].Value gives "http://www.domain.com/T60B8JK2WT/"
m.Groups["href"].Captures[1].Value gives "http://www.domain.com/5FBLQYBQTV/"
m.Groups["text"].Captures[0].Value gives "KungFu Panda - Legends of Awesomeness (2011)(1 - 22)"
m.Groups["text"].Captures[1].Value gives "KungFu Panda - Legends of Awesomeness (2011)"

NgocThanh_89 27-Jul-12 0:04am    
hi, thanks you very much, i have one more question is how i can count the number of "a" tag? With above example it will return 2.
I have using :
Regex.Match(postContent, "\\[down](<a[^><]+href>[^\"]+)\"[^<]*(?<text>[^<]*)\\s*)+\\[/down]", RegexOptions.IgnoreCase).Groups["href"].Length;
But it always return 0.
Thanks :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900