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

Better handling of extra PCRE2 regex options #15321

Open
Blacksmoke16 opened this issue Jan 6, 2025 · 0 comments
Open

Better handling of extra PCRE2 regex options #15321

Blacksmoke16 opened this issue Jan 6, 2025 · 0 comments

Comments

@Blacksmoke16
Copy link
Member

Discussion

I recently ran into a situation where I needed to use a regex with the Regex::CompileOptions::DOLLAR_ENDONLY option. However after using the Regex.new(String) overload to be able to set the option, the regex caused a PCRE2 stack size limit exceeded error. What ultimately ended up happening was the string being passed to Regex.new was like "[\|]", but was being interpreted as "[|]", changing the semantics of the regex.

The solution was to use %q() such that it was treated similar to a regex literal, which does not have this problem. So the root problem is that if you need to use regex modifiers that are not supported via a regex literal, you have to use the string version.

It would be nice to improve this use case, of which we have a few options that I could think of:

  1. Add some additional modifiers to allow using regex literals
  2. Add an additional Regex.new overload that accepts a Regex and passes it thru via #source. Would be kind of wasteful given it involves an extra Regex instance, but would allow passing extra options while still being able to use a literal for its ease of use and compile time checks.
  3. Possibly just document that %q or similar should be used when using Regex.new(String)
  4. TBD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant