Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →
instance method
Regexp#timeout
() -> ::Float?
rxp.timeout → float or nil
re.c
View on GitHub ↗
static VALUE
rb_reg_timeout_get(VALUE re)
{
rb_reg_check(re);
double d = hrtime2double(RREGEXP_PTR(re)->timelimit);
if (d == 0.0) return Qnil;
return DBL2NUM(d);
}
It returns the timeout interval for Regexp matching in second. nil means no default timeout configuration.
This configuration is per-object. The global configuration set by Regexp.timeout= is ignored if per-object configuration is set.
Example
re = Regexp.new("^a*b?a*$", timeout: 1) re.timeout #=> 1.0 re =~ "a" * 100000 + "x" #=> regexp match timeout (RuntimeError)