Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →
instance method
Regexp#fixed_encoding?
fixed_encoding? → true or false
re.c
View on GitHub ↗
static VALUE
rb_reg_fixed_encoding_p(VALUE re)
{
return RBOOL(FL_TEST(re, KCODE_FIXED));
}
Returns false if self is applicable to a string with any ASCII-compatible encoding; otherwise returns true:
Example
r = /a/ # => /a/ r.fixed_encoding? # => false r.match?("\u{6666} a") # => true r.match?("\xa1\xa2 a".force_encoding("euc-jp")) # => true r.match?("abc".force_encoding("euc-jp")) # => true r = /a/u # => /a/ r.fixed_encoding? # => true r.match?("\u{6666} a") # => true r.match?("\xa1\xa2".force_encoding("euc-jp")) # Raises exception. r.match?("abc".force_encoding("euc-jp")) # => true r = /\u{6666}/ # => /\u{6666}/ r.fixed_encoding? # => true r.encoding # => #<Encoding:UTF-8> r.match?("\u{6666} a") # => true r.match?("\xa1\xa2".force_encoding("euc-jp")) # Raises exception. r.match?("abc".force_encoding("euc-jp")) # => false