Using jQuery you don't need a complex regex, you can easily parse the HTML and use the DOM:
var s = "<p>one</p> <p align='center'>two</p>";
var wrapper = $('<div />').html(s);
var text = wrapper.text();
In this case $(s).text()
would have also worked, but it will fail if you have free text on the first level (e.g. <p>1</p>2
), so I usually avoid it.
Note that the result here is "one two"
(not "onetwo"
), because you have a space between the <p>
tags.
If that's a problem, you can use wrapper.children().text()
or wrapper.find('p').text()
, for example, according to your exact needs.
Working example: http://jsbin.com/osidi3