Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to split between two capital letters?

Tags:

regex

split

ruby

I have the following array:

a = ["CH3", "CH2"]

and I'd like to split this between two capital letters using a reg expression to display: a= ["C", "H3", "C", "H2"] How do you do this?

so far I've tried:

a.each { |array|
x = array.scan(/[A-Z]*/)
puts a
}

returns: 
CH
CH

Thanks in advance!

like image 451
JZ. Avatar asked Jul 22 '10 18:07

JZ.


1 Answers

You could try this:

s.scan(/[A-Z][^A-Z]*/)
like image 88
Mark Byers Avatar answered Oct 21 '22 10:10

Mark Byers