JSFiddle - React, Tailwind, and code Playground
JavaScript
const str1 = '<style> div { color: red; } a { color: green; } </style>hello<div></div><div><a>hello</a></div>'
const str2 = '<style> div { color: red; } div > a { color: green; } </style>hello<div></div><div><a>hello</a></div>'
const regex = /<style[^>]*>([^>]*?)<\/style>/g
const matches1 = str1.match(regex)
const matches2 = str2.match(regex)
console.log(matches1, matches2)