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).
This method was discussed in #19104. I'm not sure the name is best.
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.
I would like to propose @make_now_just (Hiroya Fujinami) as a committer. He has made a great improvement to the Regexp engine. Ruby's Regexp engine is in a state of its own fork from onigmo, and he is a valuable person who can maintain it. @matz (Yukihiro Matsumoto) What do you think?
Note: I have spoken directly with @make_now_just (Hiroya Fujinami) and he has agreed with my proposal to a committer, and I am proposing it.