From: Avi Bryant Date: 2001-03-24T19:13:51+09:00 Subject: [ruby-talk:13169] Re: capturing regex matches. > > > Is there a shortcut like: > > > if ((command) = part =~ /#{@pre}\s*(.*?)\s*#{@post}$/s) > > > puts "command: #{command}" > > > end > Or this: > > if command = /#{@pre}\s*(.*?)\s*#{@post}$/s.match(part) > puts "command: #{command[1] || 'not found'}" > end Or this: if ((command, junk) = /#{@pre}\s*(.*?)\s*#{@post}$/s.match(part)) puts "command: #{command || 'not found'}" Of course, that syntax makes more sense when you're actually expecting two or more matches, and you don't need the "junk" variable... Avi