I have a string:
s=\"123--abc,123--abc,123--abc\"
I tried using Ruby 1.9\'s new feature \"named groups\" to fetch all named group info:
Named captures are suitable only for one matching result.
Ruby's analogue of findall
is String#scan. You can either use scan
result as an array, or pass a block to it:
irb> s = "123--abc,123--abc,123--abc"
=> "123--abc,123--abc,123--abc"
irb> s.scan(/(\d*)--([a-z]*)/)
=> [["123", "abc"], ["123", "abc"], ["123", "abc"]]
irb> s.scan(/(\d*)--([a-z]*)/) do |number, chars|
irb* p [number,chars]
irb> end
["123", "abc"]
["123", "abc"]
["123", "abc"]
=> "123--abc,123--abc,123--abc"