I have a text file that contains an HTML code, and I want to take only specific tags and save them using C#!
I was thinking to do it with few Regex lines, is it the best and easiest way to do so?! or there’s an easier function in C# that can do it?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Using Regex is probably not the best way to do this, actually I would say that it’s one of the numerous “bad” ideas which you could think of.
You might want to look into using the HTMLAgilityPack: it will parse the HTML, create a tree of nodes which you can navigate and you will be able to look at the tags which you’re interested without doing any “crazy” regex. You’ll save yourself a lot of trouble if you avoid regex, since HTML as it is found in the wild can be poor, nasty and brutish, though quite often far from short.