fork download
  1. text = "11234566666678"
  2. # Variant a:
  3. results = []
  4. text.scan(/(\d)\1+/) { results << Regexp.last_match(0) }
  5. p results # => ["11", "666666"]
  6. # Variant b:
  7. p text.scan(/((\d)\2+)/).map(&:first) # => ["11", "666666"]
  8. # Variant c:
  9. p text.gsub(/(\d)\1+/).to_a # => ["11", "666666"]
  10.  
Success #stdin #stdout 0.01s 6276KB
stdin
Standard input is empty
stdout
["11", "666666"]
["11", "666666"]
["11", "666666"]