Why does JS method replace() work incorrect in the latest version of Safari?

Анна Янкович

Why does JS method replace() work incorrect in the latest version of Safari (11.1) with "$<" in the second argument?

Example:

"aaaXXXbbb".replace(/XXX/, '_before_$<_after_')

Actual result:

"aaa$<_after_bbb"

Expected result:

"aaa_before_$<_after_bbb"

PS: "$$" inserts a "$" and solves this problem

Joe Clay

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Why does the string replace method not work

Why using the latest url_launcher 6.1.2 not work with pdfs but previous version does?

Why does require choose the latest version of a gem?

Why does ScrollTop position not work on mobile Safari?

Why does my code not work in Safari or Opera?

Why does select() not work on Safari with ReactJS?

Nuget showing incorrect version as latest

Why Router link does not work in Firefox and IE but working fine in Safari and Chrome in vue js?

Why does this setter method not work?

Why does the applicationWillResignActive method not work?

Why pandas DataFrame replace method does not work (inplace=True argument is used)

Why .replace method doesn't work this way?

The str_replace method does not work in php

How does str.replace() method work?

ssh-host-config does not work on latest Windows 10 version

Why does Laravel-mix "version" work locally for JS and SASS but on remote server only works for JS?

Why does String.replace not work?

Why does gsub/sub not work to replace ".."?

Pandas replace regex: why this negation does not work

Why does the replica work replace in c++?

Why does apt-get upgrade not install the latest PHP version?

Why does the latest version of the forge viewer break my onClick listener?

getNode() method not found in gatsby-node.js with the latest version of Gatsby

Why does this maven JDA dependency version not work?

Why does my version of strcmp not work?

Why does this version mysqli result work?

Why does adding tailrec make a incorrect kotlin corecursion work?

why js .replace() work incorrectly in double letters?

Why does Canvas::drawArc method draw incorrect angles?

TOP Ranking

HotTag

Archive