admin管理员组

文章数量:1278985

I'm trying to remove all from a string.

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

Can anyone show me where I'm going wrong?

I'm trying to remove all from a string.

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

Can anyone show me where I'm going wrong?

Share Improve this question asked Aug 16, 2012 at 13:42 Mark PriceMark Price 5901 gold badge8 silver badges19 bronze badges 3
  • 1 Notice where syntax highlighting breaks. – Oleg V. Volkov Commented Aug 16, 2012 at 13:52
  • 1 Are you trying to remove the style tags along with the string inside? Or only the string inside the tags? You can do quick syntax checks as described in my answer below. – Kash Commented Aug 16, 2012 at 13:57
  • It didn't matter to me if I removed the tags or not – Mark Price Commented Aug 16, 2012 at 14:28
Add a ment  | 

4 Answers 4

Reset to default 8

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

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

/<style>.*?<\/style>/

You need backreferences...

The regex:

(\<style\>).+(/\<style\>)

Would allow you to replace with backreferences by $1$2

So, <style>asdasd</style> would result in <style></style>

replace returns the processed string, so you have to store the result anywhere

see http://www.w3schools./jsref/jsref_replace.asp

本文标签: jqueryRegex to match everything between ltstylegt and ltstylegt Then Remove with JavascriptStack Overflow