此正则表达式在JavaScript中引发错误:<li id = \"[^ \"]*+ \"

ham*_*ime 1 javascript regex

我有一堆LI元素,我需要更改它的ID名称.

我将搜索的示例目标文本:

<li id="apple">blah blah blah</li>
<other stuff>
<li id="bacon">blah blah blah</li>
Run Code Online (Sandbox Code Playgroud)

我想找到的部分说:

<li id="idnamehere"
Run Code Online (Sandbox Code Playgroud)

我尝试在JavaScript中使用这行代码:

myRegExp = new RegExp('<li id="[^"]*+"', "g");
Run Code Online (Sandbox Code Playgroud)

但是我收到此错误:

"SyntaxError: Invalid regular expression: nothing to repeat"
Run Code Online (Sandbox Code Playgroud)

当我在正则表达式编辑器中尝试此表达式时,它工作正常.关于出了什么问题的任何想法?

Tim*_*ker 6

JavaScript不支持占有量词,因此[^"]*+是非法的.放下+,然后它应该工作.