-
Notifications
You must be signed in to change notification settings - Fork 22.8k
Closed
Labels
Content:JSJavaScript docsJavaScript docseffort: mediumThis task is a medium effort.This task is a medium effort.help wantedIf you know something about this topic, we would love your help!If you know something about this topic, we would love your help!
Description
@fireattack commented on Fri Nov 13 2020
Request type
- Please close this issue, I accidentally submitted it without adding any details
- New documentation
- Correction or update
Details
It says
A regular expression defined as both sticky and global ignores the global flag.
But this doesn't seem to match my observation.
console.log('##-#'.replace(RegExp('#', 'gy'), 'x'));
console.log('##-#'.replace(RegExp('#', 'y'), 'x'));
console.log('##-#'.replace(RegExp('#', 'g'), 'x'));
The above all have different behaviors:
xx-#
x#-#
xx-x
(And they're as expected.)
@fireattack commented on Fri Nov 13 2020
Same error can be seen at https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/global
Edit: a very detailed article about difference between y
, g
, yg
: https://2ality.com/2020/01/regexp-lastindex.html
Metadata
Metadata
Assignees
Labels
Content:JSJavaScript docsJavaScript docseffort: mediumThis task is a medium effort.This task is a medium effort.help wantedIf you know something about this topic, we would love your help!If you know something about this topic, we would love your help!