class Regexp::Expression::Subexpression

def flat_map(include_self = false, &block)

each expression and its level index as an array.
for every expression. If a block is not given, returns an array with
Returns a new array with the results of calling the given block once
def flat_map(include_self = false, &block)
  result = []
  each_expression(include_self) do |exp, index|
    if block_given?
      result << yield(exp, index)
    else
      result << [exp, index]
    end
  end
  result
end