Skip to content

Sticky flag doesn't entirely mask the global flag #1454

@chrisdavidmills

Description

@chrisdavidmills

@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

No one assigned

    Labels

    Content:JSJavaScript docseffort: mediumThis task is a medium effort.help wantedIf you know something about this topic, we would love your help!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions