On Sep 18, 3:48=A0am, Me Me <emanue... / tiscali.it> wrote:
> Hi all,
> I would like to know if there's a better way to parse a string and
> assing values to variables;
>
> Ex:
>
> Client=3DMPEG-4,390000,700000,24000
>
> I can do
>
> line =3D~ /(\w*)=3D([0-9A-Za-z -.:]*),([0-9]*),([0-9]*),([0-9]*)/
>
> and
>
> var1 =3D $1
> var2 =3D $2
> var3 =3D $3
> var4 =3D $4
> var4 =3D $5
>
> But I'm sure there's a better way, even considering that the number of
> parameters can increase and I don't want to write a long regular
> expression rule, that is hard to read.

s =3D "Client=3DMPEG-4,390000,700000,24000"
    =3D=3D>"Client=3DMPEG-4,390000,700000,24000"
if s =3D~ /^\w+=3D\S+(,\d+)+$/
  vars =3D s.split( /[=3D,]/ )
end
    =3D=3D>["Client", "MPEG-4", "390000", "700000", "24000"]