From: Thorsten Haude Date: 2006-08-24T04:18:00+09:00 Subject: Re: regexp or not --U3BNvdZEnlJXqmh+ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi, * Josselin wrote (2006-08-24 04:05): >I get a string person =3D 'Clara Mint" which is a full name >and I would like to find the object "id" in a collection using this =20 >full name : > >people =3D [ ["id" =3D> "1", "first" =3D> "Jack", "last" =3D> "Johnson"], = ["id"=20 >=3D> "2", "first" =3D> "Ben", "last" =3D> "Kenneth"], ["id" =3D> "3", "fir= st"=20 >=3D> "Ken", "last" =3D> "Olsen"], ["id" =3D> "4", "first" =3D> "Howard", "= last"=20 >=3D> "Wong"], ["id" =3D> "5", "first" =3D> "Clara", "last" =3D> "Mint"], [= "id"=20 >=3D> "7", "first" =3D> "Che", "last" =3D> "Guevara"]] Use regexes to get first and last name, then iterate over the collection. Untested: person =3D~ /^(.*) (.*)$/ first =3D $1 last =3D $2 people.each do |peop| if first =3D=3D peop["first"] and last =3D=3D peop["last"] print peop["id"] end end Thorsten French Kicks: Also Ran --=20 The ability to quote is a serviceable substitute for wit. - Somerset Maugham --U3BNvdZEnlJXqmh+ Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) iD8DBQFE7KjcW/x2JEBlodoRArx3AJ9VnjvVltWfD8yIxBqtP/jP/L6MqQCeO8jO 1R8AbcXGhZ5/tQRtyTXMC74= =+Mj6 -----END PGP SIGNATURE----- --U3BNvdZEnlJXqmh+--