Regex select all text between tags

basheps picture basheps · Aug 23, 2011 · Viewed 334.3k times · Source

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

Answer

PyKing picture PyKing · Aug 23, 2011

You can use "<pre>(.*?)</pre>", (replacing pre with whatever text you want) and extract the first group (for more specific instructions specify a language) but this assumes the simplistic notion that you have very simple and valid HTML.

As other commenters have suggested, if you're doing something complex, use a HTML parser.