Need regular expression to remove the a tag from the following url <a href="http://example.com">Name</a>
to output only the string "Name"
. I am using C#.net.
Any help is appreciated
Need regular expression to remove the a tag from the following url <a href="http://example.com">Name</a>
to output only the string "Name"
. I am using C#.net.
Any help is appreciated
You should be looking at Html Agility Pack. RegEx works on almost all cases but it fails for some basics or broken Html. Since, the grammar of HTML is not regular, Html Agility pack still works perfectly fine in all cases.
If you are looking for just one time this particular case of anchor tag, any above RegEx would work for you, but Html Agility Pack is your long run, solid solution to strip off any Html tags.
Ref: Using C# regular expressions to remove HTML tags
Agree with Priyank that using a parser is a safer bet. If you do go the route of using a regex, consider how you want to handle edge cases. It's easy to transform the simple case you mentioned in your question. And if that is indeed the only form the markup will take, a simple regex can handle it. But if the markup is, for example, user generated or from 3rd party source, consider cases such as these:
Following is working for me.
This will do a pretty good job:
You can try to use this one. It has not been tested under all conditions, but it will return the correct value from your example.
Here's a version that will work for only tags.
I tested it on the following HTML and it returned Name and Value only.