From: Robert Dober Date: 2009-05-14T23:37:40+09:00 Subject: Re: need to split string into letters and numbers On Thu, May 14, 2009 at 4:34 PM, James Gray wrote: > On May 14, 2009, at 9:28 AM, shawn bright wrote: > >> Hey all > > Hello. > >> 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) > > I suggest: > >  str.scan(/\d+|[a-zA-Z]+/) > > Hope that helps. > > James Edward Gray II > > ok James so you beat me to the line, but I gotta fancy 1.9 regexen instead ;) str.scan /\p{Alpha}+|\p{Digit}+/u which might help unicoders. Cheers Robert -- Si tu veux construire un bateau ... Ne rassemble pas des hommes pour aller chercher du bois, préparer des outils, répartir les tâches, alléger le travail… mais enseigne aux gens la nostalgie de l’infini de la mer. If you want to build a ship, don’t herd people together to collect wood and don’t assign them tasks and work, but rather teach them to long for the endless immensity of the sea. -- Antoine de Saint-Exupéry