\$ in regexps

Michael Day mikeday at yeslogic.com
Sat Oct 30 04:49:59 PDT 2010

[sent this to es3.x-discuss by mistake, sorry for any duplicates]


Is \$ valid inside regexps? For example:

xs = /foo\$bar/.exec("foo$bar");

This matches in Firefox. However, the spec would appear to forbid this 
interpretation, unless I'm confused again:

IdentifierStart :: $

IdentifierPart :: IdentifierStart

IdentityEscape :: SourceCharacter but not IdentifierPart

CharacterEscape :: IdentityEscape

AtomEscape :: CharacterEscape

Atom :: \ AtomEscape

 From these rules it seems that \$ is forbidden, and the only way to 
match a $ is to use a HexEscapeSequence or UnicodeEscapeSequence.

So is this a spec bug? It seems to be present in ES3 and ES5.

Or a Firefox extension?

Best regards,


Print XML with Prince!

More information about the es-discuss mailing list