From: David Vallner Date: 2006-08-18T08:00:27+09:00 Subject: Re: reading website On Fri, 18 Aug 2006 00:40:11 +0200, fabsy wrote: > Ok! > But that doesn't tell me the position of the string.. > Say that you have a textfile with the sentence "Could you pass me the > milk please?" and I make a search for the string "milk". Then I want to > know the position of where the search word starts so I can extract the > word into a variable.... How do I do that? Use String#index, or String#=~. The former works with strings and regular expressions, the latter requires regular expressions, but I think it also saves the match data into the special global variable I don't use or remember the name of... Anyhoo: >> "foobar".index "ooba" => 1 >> "foobar".index "bar" => 3 >> "foobar".index /bar/ => 3 >> "foobar".index /ooba/ => 1 For word extraction, I'm usually very, very bad doing those with substring indexes and abuse regexps wildly each and every time I need to get some piece of text out of another one. David Vallner