Skip to content

Support optional regexp flags #256

@jbergstroem

Description

@jbergstroem

In an attempt to catch additional characters while checking for case in the subject, I ran into a limitation where I need to pass the unicode flag to RegExp():

> const strings = ["information", "Information", "Ínformation", "ínformation"];
undefined
> const old = new RegExp("^(?![A-Z]).+$", "g");
undefined
> const new = new RegExp("^(?!\\p{Lu}).+$", "gu");
undefined
> strings.forEach((s) => { console.log(`${s}: ${old.test(s)}`) });
information: true
Information: false
Ínformation: true
ínformation: false
undefined
> strings.forEach((s) => { console.log(`${s}: ${new.test(s)}`) });
information: true
Information: false
Ínformation: false
ínformation: true
undefined

I see two paths here:

  1. Allow passing regex literal instead of a string to RegExp()
  2. Allow users to set the RegExp() options (currently hardcoded to g)

Which one is preferred? I can take a stab at a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions