posted 13 years ago
There are more problems here.
One is minor - what if the style tag has attributes? (Which is the point of a style tag, after all.) You probably want to match "<style" or possibly "><style.*?>" rather than "<style>".
Another problem is major - what if the <style> tag is nested within other <style> tags? How does the regex determine which tag matches which? It's possible to write a mildly complex expression that handles one level of nesting. Or a more complex expression that handles up to two levels of nesting. Or a much more complex expression that handles up to three levels. But this will be really ugly at this point. It is fundamentally impossible to write a regex that handles an arbitrary (infinite) number of levels.
Another issue is comments - what if there are some tags that have been commented out? How does the regex know to ignore them?
For these last two reasons, and probably others, it's almost always a bad, bad idea to try to parse HTML with a regex. HTML is more complicated than many people realize. However there are many good HTML parsers out there - that do not rely on using regular expressions. Use a proven HTML parser instead.