Converting a Regex Expression that works in Chrome to work in Firefox [duplicate]

和自甴很熟 提交于 2019-12-02 12:56:58

You could try to solve things without using a negative lookbehind: do the opposite, match what you do not want as well. If it is there in your callback, then make sure to not highlight.

Note: I am not sure what the negative lookahead is accomplishing at the beginning, as you could easily make sure that the search term doesn't start with the listed values and that would yield the same result, so I am letting this part aside.

let regexp = new RegExp(`(&[^;]*|</?[^>]*)?(${term})`, 'gi');
haystack.replace(regexp, (match, ignore, term) => ignore ? match : `<span class="highlight">${term}</span>`);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!