From: "zw963 (Wei Zheng)" Date: 2021-11-05T15:12:55+00:00 Subject: [ruby-core:105947] [Ruby master Bug#18291] When use =~ with named group, if regex is on the right side, variable not defined. Issue #18291 has been reported by zw963 (Wei Zheng). ---------------------------------------- Bug #18291: When use =~ with named group, if regex is on the right side, variable not defined. https://bugs.ruby-lang.org/issues/18291 * Author: zw963 (Wei Zheng) * Status: Open * Priority: Normal * Backport: 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN ---------------------------------------- Following code not work. ```rb if "Billy Zheng" =~ /(?\w+)\s+(?\w+)/ p first_name p last_name end # NameError: undefined local variable or method `first_name' for main:Object ``` But, if we switch left and right between =~ ```rb if /(?\w+)\s+(?\w+)/ =~ "Billy Zheng" p first_name p last_name end # => "Billy" # =>"Zheng" ``` I know ruby keep this same behavior since 1.9, but i am curious if we can improve this? I consider this as a bug, because that not good, when i want to use this way, i have to take care must write regexp before =~ Thank you. -- https://bugs.ruby-lang.org/ Unsubscribe: