lib/regexp-examples/helpers.rb in regexp-examples-0.4.1 vs lib/regexp-examples/helpers.rb in regexp-examples-0.4.2
- old
+ new
@@ -18,9 +18,14 @@
def self.join_preserving_capture_groups(result)
result.flatten!
subgroups = result
.map(&:all_subgroups)
.flatten
+
+ # Only save the LAST group from repeated capture groups, e.g. /([ab]){2}/
+ subgroups.delete_if do |subgroup|
+ subgroups.count { |other_subgroup| other_subgroup.group_id == subgroup.group_id } > 1
+ end
GroupResult.new(result.join, nil, subgroups)
end
def self.map_results(repeaters)
repeaters