Regex select all text between tags

2019-01-04 07:05发布

What is the best way to select all the text between 2 tags - ex: the text between all the 'pre' tags on the page.

14条回答
小情绪 Triste *
2楼-- · 2019-01-04 07:52

preg_match_all(/<pre>([^>]*?)<\/pre>/,$content,$matches) this regex will select everyting between tag. no matter is it in new line(work with multiline.

查看更多
小情绪 Triste *
3楼-- · 2019-01-04 07:55

var str = "Lorem ipsum <pre>text 1</pre> Lorem ipsum <pre>text 2</pre>";
    str.replace(/<pre>(.*?)<\/pre>/g, function(match, g1) { console.log(g1); });

Since accepted answer is without javascript code, so adding that:

查看更多
登录 后发表回答