开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜