regex - A regular expression for anchor html tag in C#? -


i need regular expression in c# anchor tag in html source codes general it's possible. consider html code:

<a id="[constant]"       href="[specific]"     >globalplatform card specification 2.2     march, 2006</a> 

by [constant] mean value constant string there no problem it. [specific] mean address simple , specific string regular expression it, simple. main problem can not handle newline character in middle of title of anchor tag. wrote regular expression works except handling newline character between title of anchor tag.

<a[\\s\\n\\r]+id=\"[constant]"[\\s\\n\\r]+href=\"[specific]"[\\s\\n\\r]*>[\\s\\n\\r]*[^\\n\\r]+[\\s\\n\\r]*</a> 

please me

you should stay away regular expressions when comes parse html , use html parser html agility pack.

and started check how simple can parse single anchor tag.

htmldocument doc = new htmldocument();  doc.loadhtml(@"<a id=""[constant]""       href=""[specific]""     >globalplatform card specification 2.2     march, 2006</a> ");  var anchor = doc.documentnode.element("a");  console.writeline(anchor.id); console.writeline(anchor.attributes["href"].value); 

beats regular expressions, don't think? :)


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -