Issue #21709 has been updated by thyresias (Thierry Lambert). Ok. Here is the code that shows the inconsistency Regexp/String for interpolation, from your examples: ```ruby # inconsistent Regexp/String interpolation behavior prefix = '\p{In_Arabic}' suffix = '\p{In_Arabic}'.encode('US-ASCII') begin re = /#{prefix}#{suffix}/ rescue => ex puts "fail: #{ex.message} (#{ex.class})" # fail: encoding mismatch in dynamic regexp : US-ASCII and UTF-8 (RegexpError) end s = "#{prefix}#{suffix}" re = /#{s}/ puts "ok: #{s.inspect} (#{s.encoding}) -> #{re.inspect} (#{re.encoding})" # ok: "\\p{In_Arabic}\\p{In_Arabic}" (UTF-8) -> /\p{In_Arabic}\p{In_Arabic}/ (UTF-8) begin re = /#{suffix}/ rescue => ex puts "fail: #{ex.message} (#{ex.class})" # fail: invalid character property name {In_Arabic}: /\p{In_Arabic}/ (RegexpError) end s = "#{suffix}" re = /#{s}/ puts "ok: #{s.inspect} (#{s.encoding}) -> #{re.inspect} (#{re.encoding})" # ok: "\\p{In_Arabic}" (UTF-8) -> /\p{In_Arabic}/ (UTF-8) ``` ---------------------------------------- Bug #21709: Regexp interpolation is inconsistent with String interpolation https://bugs.ruby-lang.org/issues/21709#change-115347 * Author: thyresias (Thierry Lambert) * Status: Open * ruby -v: ruby 3.4.7 (2025-10-08 revision 7a5688e2a2) +PRISM [x64-mingw-ucrt] * Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN ---------------------------------------- ```ruby %w(foo être).each do |s| puts "string: #{s.inspect} -> #{s.encoding}" puts "escaped: #{Regexp.escape(s).inspect} -> #{Regexp.escape(s).encoding}" end ``` Output: ``` string: "foo" -> UTF-8 escaped: "foo" -> US-ASCII string: "être" -> UTF-8 escaped: "être" -> UTF-8 ``` The result should always match the encoding of the argument. -- https://bugs.ruby-lang.org/