Here is my string. Which will contain XML string
Like below
var str= "<str>rvrv</str>rvrv<q1>vrvv</q1>vrvrv<q2>rtvrvr</q2>";
How can I remove text outside tags(text which does not belong to any tag.) using regular expression. Please help me on this.
Assuming your problem is only removing text not enclosed inside an element (and remaining code is well formed so you haven’t strings like
) you could use a regular expression like this
and this returns
Note: to detect closing tags I used a backreference
(see http://www.regular-expressions.info/brackets.html)