From: "Jan E." Date: 2012-04-11T20:21:05+09:00 Subject: Re: need to match words from setence You still haven't said what you actually want to do (and some examples don't really help), so this is only a guess: search_word = 'important' pattern = / # beginning of the string or position after whitespace (?:(?<=\s)|\A) # optional "special character": # any printable ASCII character other than [a-zA-z0-9] (?[\p{ASCII}&&\p{Graph}&&\p{^Alnum}])? # the actual search word (don't forget to escape!) #{Regexp.escape search_word} # optional "special character" \g? # end of the string or position before whitespace (?:(?=\s)|\z) /x [ 'I am looking for important message', 'I am looking for @important. message', 'I am looking for @important message', 'I am looking for important. message', 'I am looking for importantdata message', 'I am looking forimportant. message', 'I am looking @@important%. message' ].each do |test_string| puts "#{test_string}: #{not test_string.match(pattern).nil?}" end But again: This is only a guess. The pattern may not work in special cases, and there may be much better solutions (without the obscure special chars). But we won't find out unless you tell us what this whole thing is for. -- Posted via http://www.ruby-forum.com/.