Javascript RegEx “invalid quantifier”
-
19-04-2021 - |
Domanda
var search = new RegExp("<span class=\"highlight\">(?<text>.*)</span>", "g");
Is there something wrong with the RegEx? Firebug just says "invalid quantifier". Thats it, no more information.
Soluzione
The question mark quantifier is wrong there. You want to match and collect between the brackets ()
. Doing (?
is wrong, if you want to match (
you should escape the brackets.
var search = new RegExp("<span class=\"highlight\">(<text>.*)</span>", "g");
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow