How to match last word?

Hi,all
I has a script to match ‘Transfer dbf to SQLServer’, the last
comand successfully ended.But I found no way to match last
command.Whoever can help me?

main.rb
string=’
Program begin at 2006-11-05T15:01:13+0800
Change image name to lower begin at 2006-11-05T15:01:13+0800
Change image name to lower end at 2006-11-05T15:01:14+0800
Transfer dbf to SQLServer begin at 2006-11-05T15:01:14+0800
Transfer dbf to SQLServer end at 2006-11-05T15:01:15+0800
Modify Tables begin at 2006-11-05T15:01:15+0800

re=/\n{0,1}(.+?)\s+(end\s+at)(.+?)\n/i
re.match(string)
puts $1,$2,$3,$4

The string is came from a file,so the “\n” maybe ommited,but
/\n{0,1}(.+?)\s+(end\s+at)(.+?)(\n|\Z)/i didn’t work.
This form of regular expresion always match ‘Change image name to
lower’.($2)

camenix [email protected] wrote:

Transfer dbf to SQLServer begin at 2006-11-05T15:01:14+0800
lower’.($2)

string=’
Program begin at 2006-11-05T15:01:13+0800
Change image name to lower begin at 2006-11-05T15:01:13+0800
Change image name to lower end at 2006-11-05T15:01:14+0800
Transfer dbf to SQLServer begin at 2006-11-05T15:01:14+0800
Transfer dbf to SQLServer end at 2006-11-05T15:01:15+0800
Modify Tables begin at 2006-11-05T15:01:15+0800

puts string.scan(%r{^(.)\s+(?:begin|end) at .$})
Program
Change image name to lower
Change image name to lower
Transfer dbf to SQLServer
Transfer dbf to SQLServer
Modify Tables
=> nil

Not the most efficient RX but seems to work - at least according to what
I
gather from your posting.

Kind regards

robert

On Nov 5, 8:52 pm, “Robert K.” [email protected] wrote:

Change image name to lower end at 2006-11-05T15:01:14+0800
Transfer dbf to SQLServer begin at 2006-11-05T15:01:14+0800
ap> > Transfer dbf to SQLServer end at 2006-11-05T15:01:15+0800

string='Program begin at 2006-11-05T15:01:13+0800
Modify Tables
=> nil

Not the most efficient RX but seems to work - at least according to what I
gather from your posting.

Kind regards

robert

It worked!
re=/^(.+?)\s+(end\s+at)(.+?)$/i
puts s.match(re)
result:Change image name to lower end at 2006-11-05T15:01:14+0800
$2==Change image name to lower
puts s.scan(re)
result:
Change image name to lower
end at
2006-11-05T15:01:14+0800
Transfer dbf to SQLServer
end at
2006-11-05T15:01:15+0800
$2==Transfer dbf to SQLServer

appreciate your help.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs