From: janosch-x via ruby-core Date: 2026-11-23T18:31:04+00:00 Subject: [ruby-core:127683] [Ruby Feature#11309] Iterator over string matches Issue #11309 has been updated by janosch-x (Janosch M�ller). i think this is a duplicate of #5606, #5749, #6802 ---------------------------------------- Feature #11309: Iterator over string matches https://bugs.ruby-lang.org/issues/11309#change-120194 * Author: sawa (Tsuyoshi Sawada) * Status: Open ---------------------------------------- This was hinted from a problem in stackoverflow (http://stackoverflow.com/questions/31074050/build-list-of-strings-containing-substrings-separated-by-an-from-a-string/31075511#31075511). Suppose there is a string: s = "a_b_c_d_e" To get an array of pre-matches that result from matching `s` with `"_"`, I can do this: a = [] s.scan("_"){a.push($`)} a # => ["a", "a_b", "a_b_c", "a_b_c_d"] But this looks too Perlish. I thought it would be nice if there is a method on `String` that creates an enumerator over matches so that I can do something like this: "a_b_c_d_e".some_method("_").with_object([]){|m, a| a.push(m.post_match)} # => ["a", "a_b", "a_b_c", "a_b_c_d"] where `m` is the last matchdata instance at that point. I believe such method would have wider application. -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/