\$ in regexps

Brendan Eich brendan at mozilla.com
Sat Oct 30 09:41:16 PDT 2010

On Oct 30, 2010, at 4:49 AM, Michael Day wrote:

> /foo\$bar/.exec("foo$bar")

This works in all browsers I can test atm (Chrome, Firefox, Opera, Safari).

It's an old de-facto standard, going back to the dawn of RegExp in Netscape 4-era SpiderMonkey (pre-ES3), and based on lots of Unix precedent: \ followed by any non-special char means literal next.

It is a bit future-hostile, or was 12 years ago -- we can't add more escapes easily. But that decision can't be recalled and changed, and anyway, a fixed set of escapes may be best on the Web.

ES3 and ES5 didn't codify it. Harmony should. Thanks for pointing it out.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20101030/d206f1e7/attachment.html>

More information about the es-discuss mailing list