Skip to content
This repository was archived by the owner on Feb 18, 2025. It is now read-only.
This repository was archived by the owner on Feb 18, 2025. It is now read-only.

Ensure the result works with the u flag #52

@domenic

Description

@domenic

I recently enabled the ESLint rule which encourages always using the u flag. When doing so, I found out that my custom regexp escaper, which was

function escapeRegExp(str) {
  return str.replace(/[-[\]/{}()*+?.\\^$|]/ug, "\\$&");
}

was overzealous, and would cause new RegExp(escapeRegExp(input), "ug") to fail when the input string contained a -.

This probably has some intersection with discussions in other threads, e.g. if some delegates require that the result escape - so that it can work in situations like new RegExp("[" + RegExp.escape(input) + "]", "ug"), such a requirement prohibits the result from working in situations like new RegExp(RegExp.escape(input), "ug").

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