From: "phluid61 (Matthew Kerwin)" Date: 2013-01-03T05:42:40+09:00 Subject: [ruby-core:51223] [ruby-trunk - Bug #7566] Escape (\u{}) forms in Regexp literals Issue #7566 has been updated by phluid61 (Matthew Kerwin). brixen (Brian Ford) wrote: > But as my example shows, if the bytes were in a literal String used to create the Regexp, they are already converted. And everything works just fine. No it doesn't. There are no literal strings in your example. The closest I can see is you extracting a source string from the Regexp, but I don't think that's doing what you think it is. irb(main):001:0> re = /[\\\u{5d}]/ => /[\\\u{5d}]/ irb(main):002:0> re.source => "[\\\\\\u{5d}]" If you meant this: irb(main):003:0> s = "[\\\u{5d}]" => "[\\]]" irb(main):004:0> re2 = Regexp.new s => /[\]]/ You get an entirely different Regexp. They will both match the string "ab]c" because they both include the ']' character in their character class. Incidentally: irb(main):005:0> re =~ "ab\\c" => 2 irb(main):006:0> re2 =~ "ab\\c" => nil > What's the rationale for not converting \u{}? Just because it is *an* escape sequence doesn't mean it is a *Regexp* escape sequence. Why are they treated the same? They aren't. If it helps, consider that _no_ Regexp escape sequences are treated the same as String escapes. \\ is a String literal escape sequence that is interpolated to the byte \x5C \\ is a Regexp literal escape sequence that instructs the engine to match the byte \x5C \u{} is a String literal escape sequence that is interpolated to a codepoint \u{} is a Regexp literal escape sequence that instructs the engine to match a codepoint \b is a String literal that is interpolated to the byte \x08 \b is a Regexp literal that instructs the engine to match a word boundary > It creates inconsistency between two identical Regexps except that one came from a String or Regexp literal with interpolation. No, if the Regexps were identical they would be identical. As you can see above, re and re2 are not identical, and no one should expect them to be. ---------------------------------------- Bug #7566: Escape (\u{}) forms in Regexp literals https://bugs.ruby-lang.org/issues/7566#change-35183 Author: brixen (Brian Ford) Status: Rejected Priority: Normal Assignee: Category: core Target version: 2.0.0 ruby -v: ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin10.8.0] Why are \u{} escape sequences in Regexp literals not converted to bytes like they are in String literals? https://gist.github.com/4290155 Thanks, Brian -- http://bugs.ruby-lang.org/