首页 > 解决方案 > 正则表达式导致 chrome 挂起 - JS

问题描述

我有一个搜索方法,我正在动态创建一个正则表达式。
例如:搜索词=“一个词”。

正则表达式如下所示:

(\\s*<[^>]+>\\s)*three(\\s*<[^>]+>\\s)*four

由于某种原因,它导致 chrome 浏览器挂起。
解决该问题的任何帮助将不胜感激

[编辑]

搜索到的区域如下所示:

<span id="1" title="bbox 483 1557 715 1602; x_wconf 96"><strong><em>one</em></strong></span> 
<span id="2" title="bbox 738 1557 986 1592; x_wconf 77"><strong><em>two</em></strong></span>
<span id="3" title="bbox 483 1557 715 1602; x_wconf 96"><strong><em>thre</em></strong></span> 
<span id="4" title="bbox 738 1557 986 1592; x_wconf 77"><strong><em>four</em></strong></span>
<span id="5" title="bbox 483 1557 715 1602; x_wconf 96"><strong><em>five</em></strong></span> 
<span id="6" title="bbox 738 1557 986 1592; x_wconf 77"><strong><em>six</em></strong></span>

因此,如果我正在寻找“三四”,我应该收到这两个元素:

<span id="3" title="bbox 483 1557 715 1602; x_wconf 96"><strong><em>three</em></strong></span> 
<span id="4" title="bbox 738 1557 986 1592; x_wconf 77"><strong><em>four</em></strong></span>

标签: javascriptregex

解决方案


推荐阅读