Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support optional regexp flags #256

Open
jbergstroem opened this issue Feb 13, 2024 · 3 comments
Open

Support optional regexp flags #256

jbergstroem opened this issue Feb 13, 2024 · 3 comments

Comments

@jbergstroem
Copy link

jbergstroem commented Feb 13, 2024

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.

@amannn
Copy link
Owner

amannn commented Feb 15, 2024

Allow passing regex literal instead of a string to RegExp()

Can you elaborate how that would work?

@jbergstroem
Copy link
Author

jbergstroem commented Feb 15, 2024

Allow passing regex literal instead of a string to RegExp()

Can you elaborate how that would work?

Removing the option flag:

const re = new RegExp(/^(?!\p{Lu}).+$/gu);

Edit: ..or do you mean how we would support both types in the code path?

@amannn
Copy link
Owner

amannn commented Feb 16, 2024

So this is where we read the subjectPattern from the user:

subjectPattern = ConfigParser.parseString(process.env.INPUT_SUBJECTPATTERN);

… and here we construct the regex based on it:

const match = result.subject.match(new RegExp(subjectPattern));

I understand that we could accept another option for providing the flags:

new RegExp(subjectPattern, subjectPatternFlags)

I'd just be curious if there's another option since you've mentioned that you can think of two.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants