Issue #22491 has been updated by k0kubun (Takashi Kokubun). Backport changed from 3.3: REQUIRED, 3.4: DONE, 4.0: REQUIRED to 3.3: REQUIRED, 3.4: DONE, 4.0: DONE ruby_4_0 commit:ebf8b9e8211ebaaf2c5b0bc86b4a835da5f3d593, commit:f9537330eec7d133e5e0031239e6b8bd41ef0218 merged revision(s) commit:b4e5cb26164848f4d5b775a624533c4583a73264, commit:7ec5076439961159c5ce8ebba4416879eb684392. ---------------------------------------- Bug #22491: The number of captures may change depending on the encoding of the target string https://bugs.ruby-lang.org/issues/22491#change-119981 * Author: mame (Yusuke Endoh) * Status: Closed * Backport: 3.3: REQUIRED, 3.4: DONE, 4.0: DONE ---------------------------------------- The number of captures of a Regexp may change depending on the encoding of the target string. ```ruby E = "stateless-ISO-2022-JP" a = "あ".encode("EUC-JP").encode(E) re = Regexp.new("()()#".encode(E) + a + "()()".encode(E), Regexp::EXTENDED) p re.match("ab".encode(E)).size #=> 3 p re.match(a).size #=> 5 (expected: 3) ``` -- https://bugs.ruby-lang.org/