From: Karuppasamy M Date: 2011-03-05T09:16:19+09:00 Subject: Re: printing regex results --20cf30433fe6d650ef049db12b68 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable try this, irb(main):001:0> str =3D "aaaDDDbDDDcDDDgHHyHjHJkkjUUh" =3D> "aaaDDDbDDDcDDDgHHyHjHJkkjUUh" irb(main):002:0> arr =3D str.scan(/([A-Z]{3}[a-z]{1}[A-Z]{3})/) =3D> [["DDDbDDD"]] irb(main):009:0> puts arr[0] DDDbDDD =3D> nil Thanks & Best Regards, M. Karuppasamy On Sat, Mar 5, 2011 at 4:46 AM, 7stud -- wrote: > "I=C3=B1aki Baz Castillo" wrote in post #985525: > > 2011/3/4 New C. : > >> My code is: > >> > >> str =3D "aaaDDDbDDDcDDDgHHyHjHJkkjUUh" > >> arr =3D str.scan(/([A-Z])\1{2}[a-z]\1{3}/) > >> print arr > >> > >> The match is DDDbDDD but the arr prints only the first letter D. > >> How do I get it to print the full string ("DDDbDDD")? > > > > I don't know why, but using [] rather than #scan does the work: > > > > str =3D "aaaDDDbDDDcDDDgHHyHjHJkkjUUh" > > arr =3D str[ /([A-Z])\1{2}([a-z])\1{3}/ ] > > print arr > > > > =3D> "DDDbDDD" > > ...but: > > puts arr.class > > --output:-- > String > > -- > Posted via http://www.ruby-forum.com/. > --20cf30433fe6d650ef049db12b68--