regexp which allows free text and html tags
I need som开发者_运维技巧e help in order to create a regular expression which allows me to insert free text and nested html tags.
This is an example of what I mean: the regexp will validate this text
Free text <a href="http://www.mysite.com">this is a <b>test</b></a>
and
Free text <a href="http://www.mysite.com">this is a test</a>
but it won't validate this (because the tag "a" isn't closed)
Free text <a href="http://www.mysite.com">this is a <b>test</b>
Is someone able to help me? Thank you in advance.
If the full extent of the input is what you've listed above, you can use the following:
<a[^>]+>.*?</a>
If it's a ton of code, you could create 2x regexes:
<a[^>]+>
</a>
and compare the total number of matches for each.
精彩评论