
Issue #19194 has been updated by hsbt (Hiroshi SHIBATA).
May I merge the pull request on GitHub?
Yes, you can merge it. I meant commit and push to master branch directly or merge pull-request. ---------------------------------------- Feature #19194: Add Regexp.linear_time? https://bugs.ruby-lang.org/issues/19194#change-100619 * Author: make_now_just (Hiroya Fujinami) * Status: Assigned * Priority: Normal * Assignee: make_now_just (Hiroya Fujinami) * Target version: 3.2 ---------------------------------------- I suggest adding a new method named `Regexp.linear_time?` to check if matching against a given regexp can be completed in linear time by the optimization introduced in #19104 (GitHub PR [#6486](https://github.com/ruby/ruby/pull/6486)). This method was discussed in #19104. I'm not sure the name is best. # Example ``` Regexp.linear_time?(/a/) # => true Regexp.linear_time?(/(a|a)*\1/) # => false, because this uses a back-reference. # This can accept a regexp source string and flags like `Regexp.new`. Regexp.linear_time?('a') # => true Regexp.linear_time?('a', Regexp::IGNORECASE) # => true ``` For example, this method is useful for implementing a Rubocop rule to check a regexp is ReDoS safe. # Implementation Implementation is done at GitHub PR [#6901](https://github.com/ruby/ruby/pull/6901). See the details there. -- https://bugs.ruby-lang.org/