From: "stomar (Marcus Stollsteimer)" Date: 2012-09-23T22:40:45+09:00 Subject: [ruby-core:47660] [ruby-trunk - Bug #7042] String#=~ is not equal to Regexp#=~ Issue #7042 has been updated by stomar (Marcus Stollsteimer). =begin From the documentation for Regexp: "When named capture groups are used with a literal regexp on the left-hand side of an expression and the =~ operator, the captured text is also assigned to local variables with corresponding names." Of course, this does not really answer the question regarding the "why". Regards, Marcus =end ---------------------------------------- Bug #7042: String#=~ is not equal to Regexp#=~ https://bugs.ruby-lang.org/issues/7042#change-29685 Author: Hanmac (Hans Mackowiak) Status: Open Priority: Normal Assignee: Category: Target version: ruby -v: ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux] i found out that string =~ regexp is not equal to regexp =~ string when you use named captures: "6:15 PM" =~ /(?\d+):(?\d+) (?A|P)M/; p hour,minute,pm # works not /(?\d+):(?\d+) (?A|P)M/ =~ "6:15 AM"; p hour,minute,pm # works i wonder why is that so ? -- http://bugs.ruby-lang.org/