I have a bunch of LI elements for which I need to change the ID names of.
Example target text I would search:
<li id="apple">blah blah blah</li>
<other stuff>
<li id="bacon">blah blah blah</li>
I would want to find just the part that says:
<li id="idnamehere"
I tried using this line of code in JavaScript:
myRegExp = new RegExp('<li id="[^"]*+"', "g");
However I get this error:
"SyntaxError: Invalid regular expression: nothing to repeat"
When I try this expression in a regular expression editor, it works fine. Any ideas as to what’s going wrong?
there is no entity for the
+to repeat. decide if you want to use+or*, i.e. (i removed the escapes)to match one-or-more-character-ids or
to match empty id, too. furthermore you don’t need explicit lazy or greedy matching if you use the unambiguous way you did:
*?and*mean the same in your case, i.e. “match everything until you encounter an quotation mark.”but generally: don’t parse XML with regular expressions, as the XML parsers built in your browser normally do a better job than you.