Forget about the answers that try to fix your regex. Don't do it with regex.
Instead, get the elements and map their textContent to an array:
let res = Array.from(document.getElementsByTagName('p')).map(e => e.textContent);
console.log(res);
<p>foo</p><p>bar</p>
If you only have this string and it is not a part of the document, create an element and parse it then (you don't even need to append the element to the DOM):
let s = "<p>foo</p><p>bar</p>";
let el = document.createElement('div');
el.innerHTML = s;
let res = Array.from(el.getElementsByTagName('p')).map(e => e.textContent);
console.log(res);
If you're doing this in node, you can use cheerio:
const cheerio = require('cheerio')
let html = "<p>foo</p><p>bar</p>";
const $ = cheerio.load(html);
let res = [];
$('p').each((i,e) => res.push($(e).text()));
console.log(res);
If you are doing this in any other environment, changes are extremely high that there's a DOM/XML/HTML parser available, too.
|<\/p>/g);`
– Axnyff Aug 03 '17 at 15:10tags. I need to modify the stuff between with all the other HTML-Tags that may be or may be not be inside those tags.
– Yashia Aug 03 '17 at 17:59