Ruby 4.0 リファレンスマニュアル

instance method Regexp#timeout

timeout -> Float | nilRuby 3.2 から[permalink][rdoc][edit]

その正規表現のマッチにかける時間の上限を秒数で返します。

上限が設定されていない場合は nil を返します。

この設定は正規表現ごとのもので、Regexp.new の timeout キーワード引数で指定します。設定されている場合、Regexp.timeout によるプロセス全体の設定よりも優先されます。

re = Regexp.new("^(a|a)*$", timeout: 0.5)
p re.timeout      # => 0.5

p /^(a|a)*$/.timeout # => nil

[SEE_ALSO] Regexp.timeout, Regexp.timeout=