正则表达式用开始和结束替换多次出现的内容(Regular expression to replace multiple occurrence of content with start and end)
我有一个像下面的字符串
Mickey <script> 333</script> 1 <script>eee</script> 2 <script>edddde</script> 3我希望它像下面一样(将所有的开始脚本和结束脚本标记替换为空白)
米奇1 2 3
当我在下面尝试时(它将替换第一个和最后一个脚本标记之间的整个内容
data = data.replace(/<script>.*<\/script>/,"")我得到米奇3
I have a string like below
Mickey <script> 333</script> 1 <script>eee</script> 2 <script>edddde</script> 3and I want it to be like below (replace all occourrence of start script and end script tag with blank)
Mickey 1 2 3
When I try below (it replaces whole content between first and last script tag
data = data.replace(/<script>.*<\/script>/,"")I get Mickey 3
最满意答案
使用非贪婪的操作符:
data = data.replace(/<script>.*?<\/script>/g, "");Use the non-greedy operator:
data = data.replace(/<script>.*?<\/script>/g, "");更多推荐
发布评论