From: come Date: 2007-06-12T16:35:03+09:00 Subject: Re: extracting numbers from a string If you just want to extract one number from a string, you could write something like : if a="DSC_1234.jpg" then a[/\d+/] will give you the first longest string of numbers, so 1234. If you want to be more precise, you could use parenthesis to extract the exact portion you want, like : a[/DSC_(\d+)\.jpg/,1] (<=> a.match(/DSC_(\d+)\.jpg/)[1]) or even : a[/\ADSC_(\d+)\.jpg\Z/,1] On 12 juin, 08:45, Matt Jones wrote: > I have filenames from various digital cameras: DSC_1234.jpg, > CRW1234.jpg, etc. What I really want is the numeric portion of that > filename. How would I extract just that portion? > > I expect it to involve the regex /\d+/, but I'm unclear how to extract a > portion of a string matching a regex. > > Thank you > > -- > Posted viahttp://www.ruby-forum.com/.