Wish Ruby had a String#each_sub method that returned each string with each matching substring replaced, individually

"A1A2A3".each_sub('A','X')
# => ["X1A2A3", "A1X2A3", "A1A2X3"]

Or String#all_indexes(substring) or String#all_matches(regexp) methods to find all occurrences of a substring or regexp.

Follow

@postmodern That *would* nice. Especially if it took a block, too. I mean there is but that's not the same.

Sign in to participate in the conversation
Ruby.social

A Mastodon instance for Rubyists & friends