Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex to match everything between <style> and </style> Then Remove with Javascript

I'm trying to remove all from a string.

runReportReq.responseText.replace(/\<style>.*?\</style>/, '')

Can anyone show me where I'm going wrong?

like image 466
Mark Price Avatar asked Nov 22 '25 16:11

Mark Price


2 Answers

Try this:

runReportReq.responseText.replace(/<style>.*?<\/style>/g, '')

You can test the validity of the regex syntax here for JavaScript with sample code:
Regex Tester

You can test the regex itself with sample input here for JavaScript:
RegexPal

like image 135
Kash Avatar answered Nov 25 '25 08:11

Kash


You've not escaped the right character, try with:

/<style>.*?<\/style>/
like image 44
Toto Avatar answered Nov 25 '25 09:11

Toto



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!