How can I get the results from both scan and split form a string – positive and negative matches? Equivalent to
def scan_and_split(string, regexp)
string.split(regexp).zip(string.scan(regexp))
end
scan_and_split("{T}: Add {W} or {U} to your mana pool. Adarkar Wastes deals 1 damage to you.", /\{[^ ]+\}/)
Expected output:
[["", "{T}"], [": Add ", "{W}"], [" or ", "{U}"], [" to your mana pool. Adarkar Wastes deals 1 damage to you.", nil]]
Use
splitwith captures.If you want a subarray for each
split/match, then applyeach_slice(2).to_ato the result.