From: "Jesús Gabriel y Galán" Date: 2009-05-14T23:40:41+09:00 Subject: Re: need to split string into letters and numbers On Thu, May 14, 2009 at 4:28 PM, shawn bright wrote: > Hey all > > I need to be able to split a string into lumps of numbers and letters. > so for example if st = "JJ542JQ83" would become ['JJ', '542','JQ',"83"] > > i have been using st.split(/([a-zA-Z]+)(?=[0-9])/) , this does pretty well > most of the time, > but also fails sometimes to do what i need it to . ( like for 202GP) > > any help would be much appreciated, thanks Try scan: irb(main):001:0> s = "JJ234AB2" => "JJ234AB2" irb(main):004:0> s.scan(/[a-zA-Z]+|[0-9]+/) => ["JJ", "234", "AB", "2"] irb(main):005:0> s = "202GP" => "202GP" irb(main):006:0> s.scan(/[a-zA-Z]+|[0-9]+/) => ["202", "GP"] Jesus.