The reason for the error is that your regex includes a positive lookbehind (?<=\s)
- a feature that the Javascript implementation of regular expressions does not provide (see Mimicking Lookbehinds in Javascript). (More precisely, the error is caused by the ?
following the un-escaped (
, when not followed by !
, =
or :
etc.)
The link you provided to a working example is a Flex application written in ActionScript 3 and that does include positive lookbehinds.
You also need to add the g
flag to the end of your regex literal to get an array of all the matches from match
, then you can sum their lengths.
Here is a working example with the positive lookbehind removed and the g
flag added: jsfiddle.
It shows a length of 163
which looks about right, but I'll leave the counting to you.
You may need to add something in place of the lookbehind or otherwise edit the regex - I'll also leave you to work that out.