Skip to content
class method · added in Ruby 3.2

Regexp.timeout=

[T < ::_ToF] (T timeout) -> T
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 · 3.4 · 3.3 · 3.2