[Wtr-general] How to pick the last word in the sentence

Chong forum-watir-users at openqa.org
Tue Jul 10 11:26:17 EDT 2007


str = "<td>What was your first pet's name?</td><td>Another sentence here</td>"
sentences = str.scan(/<td>([^<]*)/)
last_words_arr = []
for arr in sentences
  sentence = arr.first
  sentence.gsub!('?', '')
  sentence.gsub!('.', '')
  sentence.gsub!('!', '')
  last_word = sentence.split.last
  last_words_arr << last_word
end
p last_words_arr


More information about the Wtr-general mailing list