Skip to content

A global scan drops the trailing empty match: "a".match(/a*/g) is ["a"], node gives ["a",""] #9430

Description

@proggeramlug
"a".match(/a*/g)              // node ["a",""]        perry ["a"]
"ab".match(/b*/g)             // node ["","b",""]     perry ["","b"]
"a".replace(/a*/g, "<>")      // node "<><>"          perry "<>"

Same for matchAll. No flags beyond g are involved.

When the previous match ends at the end of the haystack, the scan stops instead of taking the final zero-width match that ECMAScript's RegExpExec loop produces there.

This is what makes test_parity_regex_replace_fn_lookahead diverge from node today, and it is why the /gms rows for terminator-final subjects had to be excluded from #9427's #9408 fixture — with a comment in the file pointing here.

Found while fixing #9408/#9409; independent of both.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions