Skip to content

End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

class method · added in Ruby 3.2

Regexp.timeout=

Regexp.timeout = float or nil

It sets the default timeout interval for Regexp matching in second. nil means no default timeout configuration. This configuration is process-global. If you want to set timeout for each Regexp, use timeout keyword for Regexp.new.

Example
Regexp.timeout = 1
/^a*b?a*$/ =~ "a" * 100000 + "x" #=> regexp match timeout (RuntimeError)

Ruby version changes

  1. 3.2
See also .timeout #timeout .try_convert .quote also in 4.1 · 4.0 · 3.4 · 3.3