title: regex to parse CSS from HTML string fails when child combinator is used
body: <p>I'm using the following regex in my JavaScript code to parse CSS (style tags and their contents) from a larger string of HTML code</p>
  <pre class="lang-js prettyprint-override"><code>const regex = /&lt;style[^&gt;]*&gt;([^&gt;]*?)&lt;\/style&gt;/g
  </code></pre>
  <p>This works fine, unless the CSS code contained within the style tags includes a CSS <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Child_combinator" rel="nofollow noreferrer">child combinator</a> selector (a CSS selector like <code>div &gt; a</code> for example). I imagine this has something to do with the fact that this particular selector uses <code>&gt;</code> which is also syntax used to create the actual <code>&lt;style&gt;</code> tags in HTML, but I don't understand regex well enough to know if there's a way around this?</p>
  <pre class="lang-js prettyprint-override"><code>const str1 = '&lt;style&gt; div { color: red; } a { color: green; } &lt;/style&gt;hello&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;a&gt;hello&lt;/a&gt;&lt;/div&gt;'
  const str2 = '&lt;style&gt; div { color: red; } div &gt; a { color: green; } &lt;/style&gt;hello&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;a&gt;hello&lt;/a&gt;&lt;/div&gt;'
  
  const regex = /&lt;style[^&gt;]*&gt;([^&gt;]*?)&lt;\/style&gt;/g
  
  const matches1 = str1.match(regex) // returns a match
  const matches2 = str2.match(regex) // does NOT return a match
  
  </code></pre>
  <p>here's a <a href="https://jsfiddle.net/x9d6Lcy4/" rel="nofollow noreferrer">fiddle</a></p>
  <p>is there a way to modify the regex so that it also works when the CSS code contains a <code>&gt;</code>?</p>
  <hr />
  <p><strong>UPDATE</strong></p>
  <p>A clarification based on discussion in the comments</p>
  <p>In my particular case, I'm approaching this challenge via regex (rather than say parsing a DOM via <code>document.querySelectorAll('style')</code>) because the code needs to be able to run in different contexts (the JS runtime is found in various places these days, from browsers, to node to the Adobe suite) and so I was looking for a context agnostic solution</p>
  <p>At the moment it seems @Maxt8r solution of changing the content expression to <code>[\S\s]*?</code> seems to have worked</p>