ruby-dev (Japanese) list archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-dev:52014]  [Ruby master Feature#19194] Add Regexp.linear_time?
@ 2022-12-11  5:54 make_now_just (Hiroya Fujinami)
  2022-12-12  0:56 ` [ruby-dev:52015] " mame (Yusuke Endoh)
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: make_now_just (Hiroya Fujinami) @ 2022-12-11  5:54 UTC (permalink / raw)
  To: ruby-dev

Issue #19194 has been reported by make_now_just (Hiroya Fujinami).

----------------------------------------
Feature #19194: Add Regexp.linear_time?
https://bugs.ruby-lang.org/issues/19194

* Author: make_now_just (Hiroya Fujinami)
* Status: Open
* Priority: Normal
----------------------------------------
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/

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2022-12-25  1:13 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-11  5:54 [ruby-dev:52014] [Ruby master Feature#19194] Add Regexp.linear_time? make_now_just (Hiroya Fujinami)
2022-12-12  0:56 ` [ruby-dev:52015] " mame (Yusuke Endoh)
2022-12-12  2:05 ` [ruby-dev:52016] " matz (Yukihiro Matsumoto)
2022-12-12  2:06 ` [ruby-dev:52017] " matz (Yukihiro Matsumoto)
2022-12-12  5:40 ` [ruby-dev:52020] " make_now_just (Hiroya Fujinami)
2022-12-13  7:03 ` [ruby-dev:52022] " hsbt (Hiroshi SHIBATA)
2022-12-13  7:10 ` [ruby-dev:52023] " make_now_just (Hiroya Fujinami)
2022-12-13  7:15 ` [ruby-dev:52024] " hsbt (Hiroshi SHIBATA)
2022-12-14 10:21 ` [ruby-dev:52026] " hsbt (Hiroshi SHIBATA)
2022-12-25  0:06 ` [ruby-dev:52031] " jnchito (Junichi Ito) via ruby-dev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).