$符号的特殊性

As ECMA’s define, there are some pattern in newString parameter, so, be careful about it.
(From ECMA-262 3rd Edition, but as test IE8 don’t support it.)
Specifying a string as a parameter

The replacement string can include the following special replacement patterns:

Pattern

Inserts

$$

Inserts a "$".

$&

Inserts the matched substring.

$`

Inserts the portion of the string that precedes the matched substring.

$'

Inserts the portion of the string that follows the matched substring.

$n or $nn

Where n or nn are decimal digits, inserts the n th parenthesized submatch string, provided the first argument was a RegExp object.

你可能感兴趣的:($)