How to split between two uppercase letters?

I have the following array:

a = ["CH3", "CH2"] 

and I would like to split it between two uppercase letters using the reg expression to display: a= ["C", "H3", "C", "H2"] How do you do this?

So far I have tried:

 a.each { |array| x = array.scan(/[AZ]*/) puts a } returns: CH CH 

Thanks in advance!

+6
split ruby regex
source share
1 answer

You can try the following:

 s.scan(/[AZ][^AZ]*/) 
+7
source share

All Articles