Robert Dober
5/14/2009 2:38:00 PM
On Thu, May 14, 2009 at 4:34 PM, James Gray <james@grayproductions.net> wro=
te:
> 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 =3D "JJ542JQ83" would become ['JJ', '542','JQ',"83"=
]
>>
>> i have been using st.split(/([a-zA-Z]+)(?=3D[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:
>
> =A0str.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
--=20
Si tu veux construire un bateau ...
Ne rassemble pas des hommes pour aller chercher du bois, pr=E9parer des
outils, r=E9partir les t=E2ches, all=E9ger le travail=85 mais enseigne aux
gens la nostalgie de l=92infini de la mer.
If you want to build a ship, don=92t herd people together to collect
wood and don=92t assign them tasks and work, but rather teach them to
long for the endless immensity of the sea.
--
Antoine de Saint-Exup=E9ry