开发者

How to split between two capital letters?

开发者 https://www.devze.com 2023-01-08 05:30 出处:网络
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?

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.sc开发者_Go百科an(/[A-Z]*/)
puts a
}

returns: 
CH
CH

Thanks in advance!


You could try this:

s.scan(/[A-Z][^A-Z]*/)
0

精彩评论

暂无评论...
验证码 换一张
取 消