From: 7stud -- Date: 2011-03-05T08:16:42+09:00 Subject: Re: printing regex results "IƱaki Baz Castillo" wrote in post #985525: > 2011/3/4 New C. : >> My code is: >> >> str = "aaaDDDbDDDcDDDgHHyHjHJkkjUUh" >> arr = 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 = "aaaDDDbDDDcDDDgHHyHjHJkkjUUh" > arr = str[ /([A-Z])\1{2}([a-z])\1{3}/ ] > print arr > > => "DDDbDDD" ...but: puts arr.class --output:-- String -- Posted via http://www.ruby-forum.com/.