From: Dave Thomas Date: 2008-12-27T01:56:00+09:00 Subject: Re: Regular Expression Trouble On Dec 26, 2008, at 10:41 AM, Chris Hoeppner wrote: > > /.*s?(\d?\d)x?e?(\d\d).*\.(\w{3})$/i > > It's meant to rename TV Show files, both video and subtitles. I'm > having > trouble making it match the first group however. One of the digits > should be optional, so I stuffed a ? sign there. However, it only > matches one digit, leaving strings like 12x14 with captures ["2", > "14"]. Your problem is that .* is swallowing as many characters as it can. In this case, it is swallowing up to and including the '1'. It then stops, because you've said you need at least one digit before the 'x', and that's the second \d. If you change it around to /.*(\d\d?)x/ it should work. Note that I've also removed the s?, as that can never actually be used—the .* will swallow the 's'. Regards Dave Thomas