[英]Why does this regex take so long to execute?
我创建了regex
,该regex
应该将文本移到相邻的<span>
标记中。
const fix = (string) => string.replace(/([\S]+)*<span([^<]+)*>(.*?)<\/span>([\S]+)*/g, "<span$2>$1$3$4</span>")
fix('<p>Given <span class="label">Butter</span>'s game, the tree counts as more than one input.</p>')
// Results in:
'<p>Given <span class="label">Butter's</span> game, the tree counts as more than one input.</p>'
但是,如果将没有文本触摸<span>
标记的字符串传递给它,则需要花费几秒钟来运行。
我正在Chrome
和Electron
上对此进行测试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.