J
Jedrin
I am trying to understand exactly why this reg ex works the way it
does.
The key part here is the back ref \2 which confuses me a bit as it
seems recursive in a way
that I haven't intuited quite:
s = "111221"
s.scan(/((\d)\2*)/).map(&:first)
#=> ["111", "22", "1"]
I figured out that that map(&:first)
is the same as map{|x| x.first}
so then it's this part that I don't quite understand
s.scan(/((\d)\2*)/)
#=>[["111", "1"], ["22", "2"], ["1", "1"]]
does.
The key part here is the back ref \2 which confuses me a bit as it
seems recursive in a way
that I haven't intuited quite:
s = "111221"
s.scan(/((\d)\2*)/).map(&:first)
#=> ["111", "22", "1"]
I figured out that that map(&:first)
is the same as map{|x| x.first}
so then it's this part that I don't quite understand
s.scan(/((\d)\2*)/)
#=>[["111", "1"], ["22", "2"], ["1", "1"]]