javascript Replace() 正则表达式返回语法错误

发布于 2025-01-04 18:58:19 字数 466 浏览 4 评论 0原文

我正在使用 Jquery 尝试 YQL,一些 javascript 替换正则表达式返回语法错误:

data = data.replace(/<?/body[^>]*>/g,'');
data = data.replace(/<noscript[^>]*>[Ss]*?</noscript>/g,'');
data = data.replace(/<script[^>]*>[Ss]*?</script>/g,'');
data = data.replace(/<script.*/>/,'');

有谁知道语法有什么问题以及如何修复它?

提前致谢

完整脚本:http://pastebin.com/49YUKTdV

I'm trying out YQL with Jquery, and some javascript replace regexp returns a syntax error:

data = data.replace(/<?/body[^>]*>/g,'');
data = data.replace(/<noscript[^>]*>[Ss]*?</noscript>/g,'');
data = data.replace(/<script[^>]*>[Ss]*?</script>/g,'');
data = data.replace(/<script.*/>/,'');

Does anyone know what is wrong with the syntax and how I can fix it?

Thanks in advance

Complete script: http://pastebin.com/49YUKTdV

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦里梦着梦中梦 2025-01-11 18:58:20

你的正则表达式中的 / 破坏了它,你需要将它们全部转义:

/<script.*/>/
          ^----- this one needs to be escaped

/<script.*\/>/

your /s in your regex are breaking it, you need to escape them all:

/<script.*/>/
          ^----- this one needs to be escaped

/<script.*\/>/
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文