Tom Allison wrote:

> MonkeeSage wrote:
>> Tom Allison wrote:
>>> So, how do you set a variable in a regular expression?
>> 
>> You have it right.
>> 
>>> Also, how would I match multiple lines?
>> 
>> You're right again with the //m. But you can't read line-by-line
>> (IO#each) and match across multiple lines without building some kind of
>> parser. It's usually better to just read the data into a single string
>> for multiline matches.
>> 
>> Input (multiline):
>> Received: from mail.papa.smurf (mail.papa.smurf [127.0.0.1])
>> by down / fraggle.roc
>> 
>> config = {'hostname' => 'down / fraggle.roc'}
>> line = $stdin.read
>> puts line if line =~ /^Received:.*by #{config['hostname']}/m
>> 
> 
> This prints out the entire message.

Well, if the regexp as written correctly identifies the beginning and end of
the desired area, how about this:

result = line.sub(/^(Received:.*?by #{config['hostname']}).*/m,"\\1")

puts result if result.size > 0

Note the question mark in the middle of the regexp. It means to stop at the
first match, not the last, of what follows. This change may not matter in
practice, but it is a good habit to fall into when dealing with a lot of
data. One special case might fail after thousands of successful matches.

This hasn't been tested.

-- 
Paul Lutus
http://www.arachnoid.com