I am trying to select all the text between
tags from a parent tag. How to do this. using regex
This is my sample string
<p>sddsd</p>
<pre>
<p>line 1</p>
<p>line 2</p>
<p><line 3</p>
</pre>
I want to select only this
line 1
line 2
line 3
I am using this regex, but it is selecting only first line of p tag
<pre>\n<p>(.+)<\/p>
use this website to run your regex
Please help me...
答案 0 :(得分:0)
您可以使用DOMParser()
。不需要正则表达式
var str = '<p>sddsd</p><pre><p>line 1</p><p>line 2</p><p>line 3</p></pre>';
var parser = new DOMParser();
var htmlDoc = parser.parseFromString(str, 'text/html');
console.log(htmlDoc.querySelector('pre').textContent)