From: Shajith Chacko Date: 2009-05-14T23:44:19+09:00 Subject: Re: need to split string into letters and numbers Hey, On Thu, May 14, 2009 at 9:28 AM, shawn bright wrote: > 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) You could use String#scan for this. Eg: irb(main):019:0> st = "JJ542JQ83" => "JJ542JQ83" irb(main):020:0> st.scan(/\d+|[A-Za-z]+/) => ["JJ", "542", "JQ", "83"] irb(main):021:0> st = "202GP" => "202GP" irb(main):022:0> st.scan(/\d+|[A-Za-z]+/) => ["202", "GP"] irb(main):023:0> Does that work? Shajith