Does multibyte character interfere with end-line character within a regex?

encoding, multibyte, regex, ruby, ruby-2.0

Solution

In Ruby trunk, the issue has now been accepted as a bug. Hopefully, it will be fixed.

Update: Two patches have been posted in Ruby trunk.

Problem

With this regex: ``` regex1 = /\z/ ``` the following strings match: ``` "hello" =~ regex1 # => 5 "こんにちは" =~ regex1 # => 5 ``` but with these regexes: ``` regex2 = /#$/?\z/ regex3 = /\n?\z/ ``` they show difference: ``` "hello" =~ regex2 # => 5 "hello" =~ regex3 # => 5 "こんにちは" =~ regex2 # => nil "こんにちは" =~ regex3 # => nil ``` What is interfering? The string encoding is UTF-8, and the OS is Linux (i.e., `$/` is `"\n"`). Are the multibyte characters interfering with `$/`? How?

Original source