This behavior doesn't occur in Firefox or Chrome, and I think I understand why.
A new feature has been accepted for inclusion in the next version of the ECMAScript spec called 'Regex Named Capture Groups' which, as the name suggests, allows you to assign a name to a capture group in a regular expression. One of the things added by this feature is a new addition to the replacement string syntax which allows you to interpolate the value of a named capture group.
This syntax takes the form $<captureName>
- note the $<
at the beginning!
According to the latest iteration of the spec, if you haven't closed a $<
with a corresponding >
, it should be ignored and just treated as part of the text. The behavior being displayed in your browser doesn't line up with this, and therefore I think it's quite likely that you've discovered a bug!
I'd encoruage you to report it to WebKit via the process detailed on their website.