I have never worked with binary before and after trying to solve this
problem for 3 hours im turning to the community for help

i have a text file which has entries comprised of a key written in
binary and its values written in strings (you can see an exerpt below).

I need to parse the binary and transform it into human readable hex and
parse its associated info. My reg exps dont seem to be behaving and im
wondering if its me or if its this binary text that is causing mischief
somehow. Heres a sample item

20: 
??祺ア??キ???G??????d8:completei7e10:downloadedi2046e10:incompletei1ee binary parts are always enclosed between "20:" and "d8:complete" where the 8 can be any integer(s) e.g. 5 or 23. str = File.open('textfile.txt' , 'r').readlines.join str.gsub!(/(20:)(.*?)(d\d+:)/m) do |x| $1 + $2.unpack('H*').join + $3 end The above works for some but not all of the text. It seeems to go beyond the "d8:complete" marker Heres a bigger sample set if needs be. Any tips or pointers would be greatly appreciated. d8:completei2e10:downloadedi770e10:incompletei1ee20: ??祺ア??キ???G??????d8:completei7e10:downloadedi2046e10:incompletei1ee20: 6?????? ?jュ???w???d8:completei0e10:downloadedi72602e10:incompletei1ee20: }tェスh>??????????d8:completei3e10:downloadedi7718e10:incompletei2ee20: ???C ??J<?F?0????Wd8:completei2e10:downloadedi617e10:incompletei0ee20: inc????U]~鼡?????< d8:completei3e10:downloadedi533e10:incompletei0ee20: ?<Z?<0?_!Y/????3d8:completei1e10:downloadedi281e10:incompletei0ee20: 6????i????ッ??オGd8:completei0e10:downloadedi216e10:incompletei1ee20: I?l?ォヲ7Z&????K?建??Ed8:completei4e10:downloadedi262e10:incompletei3ee20: Sm??ソ??ソ??h7r????d8:completei3e10:downloadedi787e10:incompletei0ee20: Yjスゥ?d ? 豥 bj???]VF???w仭鱧????d8:completei10e10:downloadedi505e10:incompletei16ee20: h?????\MDa???3??d8:completei2e10:downloadedi1050e10:incompletei2ee20: h????????=ゥ?ソ??????d8:completei1e10:downloadedi57e10:incompletei2ee20: mb???<GS?bオゥqT????d8:completei1e10:downloadedi3860e10:incompletei1ee20: u ??axB?z<?3d8:completei3e10:downloadedi700e10:incompletei7ee20: u[??????@2 ?4??d8:completei0e10:downloadedi658e10:incompletei3ee20: ??????a???$??#???3!COd8:completei3e10:downloadedi304e10:incompletei0ee20: ????G?_????Z?7}d8:completei3e10:downloadedi2285e10:incompletei2ee20: ??サ???「??Ga?`q???vBd8:completei6e10:downloadedi1061e10:incompletei5ee20: ?????e???ゥケソ????ゥ?j???d8:completei3e10:downloadedi2902e10:incompletei1ee20: セオッ???M?_L????ー?ld8:completei1e10:downloadedi147e10:incompletei1ee20: ィ??Y#???U? "?F?b?awd8:completei6e10:downloadedi39010e10:incompletei2ee20: ゥ?ォ?2、??1???tス??8:completei7e10:downloadedi1835e10:incompletei0ee20: ?3????L? ?)サ??̥ ?)PO??? オク?&???%L????d8:completei4e10:downloadedi3674e10:incompletei0ee20: ??ュ??E\GT??????翡ェイ?d8:completei2e10:downloadedi328e10:incompletei0ee20: ?????(????K??セ??ィ??d8:completei43e10:downloadedi9665e10:incompletei31ee20: ??????殱
??? 0h???qgd8:completei3e10:downloadedi17686e10:incompletei0ee20: ?Bコ??g??ェ????-/T???d8:completei5e10:downloadedi801e10:incompletei2ee20: ????? 4?I???{-u)ᄆ??bd8:completei3e10:downloadedi4878e10:incompletei2ee20: ???????&?Obシ??$???d8:completei4e10:downloadedi1499e10:incompletei0ee20: ?@i????t???aK?f?.??d8:completei7e10:downloadedi1745e10:incompletei3ee20: ??<シエ???B???i?\,?Ed8:completei0e10:downloadedi745e10:incompletei1ee20: ??橡???P???Zキ???????2?d8:completei1e10:downloadedi11865e10:incompletei7ee20: ??。B<?ケ?????D =イ?オ???7??????d8:completei2e10:downloadedi9246e10:incompletei2ee20:G[fJ???Y*d8:completei15e10:downloadedi3649e10:incompletei11ee20:???/Xr??J ???XA ????d8:completei3e10:downloadedi323e10:incompletei0ee20:???ョ???ッア jetei4e10:downloadedi12601e10:incompletei0ee20:aソ??????? \??@??。???8:completei3e10:downloadedi1005e10:incompletei0ee20:ct?@?+ ??e5l?d8:completei0e10:downloadedi166e10:incompletei2ee20:c?Glus?Bn、??]糾ィ?d8:completei1e10:downloadedi110e10:incompletei0ee20:j+s「??x」??i?4!???mG~d8:completei5e10:downloadedi6427e10:incompletei0ee20:|1S???M?i????? ???/~d8:completei5e10:downloadedi865e10:incompletei2ee20:}lカ???/???2k+?B????8:completei4e10:downloadedi1032e10:incompletei0ee20:??シ?u?P???????孤諒ᆬー・ᆬ綥袥ᆬᆬ・ե諒・ ュウL???ッ|????8$d8:completei0e10:downloadedi69e10:incompletei1ee20:????b"mィウ????ウ???????8:completei8e10:downloadedi9526e10:incompletei0ee20:ュ???4|コェ????屮 l?Ead8:completei15e10:downloadedi1775e10:incompletei9ee20:??A?q???kF?{D???? d8:completei5e10:downloadedi4154e10:incompletei1ee20:?03???8e10:incompletei0ee20:? 漸????+??¦?h???!d8:completei3e10:downloadedi2874e10:incompletei1ee20:ゥ??l,8H諒溥椥・鹥ォ諒 ᆬॽ・ィ祽「楽。楽・オ諒ʥカスĥ饯・??,?tQ?_??`?(?d8:completei3e10:downloadedi1536e10:incompletei21ee20:?S????el%~シュ,y????bd8:completei1e10:downloadedi111e10:incompletei1ee20:?Bd ??ケ???|e]?"?vTd8:completei2e10:downloadedi1096e10:incompletei1ee20:???セ???$????d8:completei1e10:downloadedi701e10:incompletei0ee20:?z??/??@g.3???=????d8:completei0e10:downloadedi512e10:incompletei1ee20:???????i15e10:downloadedi2161e10:incompletei8ee20:~???B?|???0篷??`hd8:completei0e10:downloadedi86e10:incompletei1ee20:話??!??\????????・俥>(???l?=????????8:completei5e10:downloadedi8917e10:incompletei1ee20:??サJg????F2???@kd8:completei7e10:downloadedi1644e10:incompletei22ee20:?"&cB:TR?}ta禰シ0+?8:completei3e10:downloadedi418e10:incompletei0ee20:????????$N?c?P???{?d8:completei8e10:downloadedi10297e10:incompletei10ee20:???>T???? ???>?????8:completei0e10:downloadedi323e10:incompletei1ee20:??v?.s?????e1+|<?Gd8:completei0e10:downloadedi1412e10:incompletei1ee20:?ャ???n、c ???ォ_???d8:completei2e10:downloadedi477e10:incompletei3ee20:?""?Rオ???????@???d8:completei0e10:downloadedi175e10:incompletei4ee20:???u??????Z?8w???>{ヲ??8:completei1e10:downloadedi5929e10:incompletei0ee20:????????ッi7MY???v??Yd8:completei1e10:downloadedi212e10:incompletei1ee20:?????f???QfC?+??d8:completei1e10:downloadedi159e10:incompletei2ee20:??ィ7ゥ?????????? can anyone help -- Posted via http://www.ruby-forum.com/.