0

I want to get html tag from the string.

I have tried this regex:

"<[\r\n ]*/?[\r\n ]*(.*?)[\r\n ]*/?[\r\n ]*>"

But it is also giving me:

< / table />

I don't want such wrong tags.

7
  • 3
    stackoverflow.com/questions/1732348/… Commented Sep 2, 2013 at 8:37
  • 7
    Regex is wrong tool for working with structutes like html, xml, etc. Use HtmlAgilityPack for parsing html. Commented Sep 2, 2013 at 8:37
  • There are quite a lot of "how do I parse html with regex" questions, the general suggestion is to avoid doing that at all and use Html Agility Pack (htmlagilitypack.codeplex.com) Commented Sep 2, 2013 at 8:37
  • Using Regex carefully and limitedly in just some certain HTML patterns would be OK. Commented Sep 2, 2013 at 8:40
  • @I4V I feel like I should start flagging such questions as duplicates of the one you linked. ;P Commented Sep 2, 2013 at 8:57

1 Answer 1

1

Try </?[^>/]*>|<[^>/]*/> or </?[^>/]+>|<[^>/]+/>. Google is your friend as well.

Sign up to request clarification or add additional context in comments.

10 Comments

From question: But it is also giving me: < / table /> I don't want such wrong tags.
I've amended my answer to accommodate for the issue pointed out, @I4V.
What about this valid html? <html><body><img src='#' /></body></html>
@ErikAllik : It is not giving me <img src='#' /> tag
@ErikAllik Or better, as mentioned in comments: HtmlAgilityPack.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.