$string = 'test #any_word';
//other cases:
//$string = 'test test #any_word';
//$string = 'test test test #any_word';
//$string = 'test test test ... #any_word';
if(preg_match('/pattern goes here.../', $string){
echo 'Matched';
}else{
echo 'Not Matched';
}
If you could explain what you're looking for, then I can tell you he pattern. So, what is the significance? Every word has an underscore in it, is that it? Or the word 'test'? Or a hash (#)? Or because the sentence consists of more than one word?