in reply to GREP/Regex - Locating Words in Sentences
Note that grep also makes use of regular expressions(in this case anyway). So realize that it may not have been your regular expressions that weren't working but rather the logic of your code.$word = shift; %sent = ( one => "This is sentence one. I wonder what the word is.", two => "This would be sentence two.", thr => "Is this sentence three. I think it is. I sure hope it is.", ); @matches = grep $sent{$_} =~ /\b$word\b/, keys %sent; print "The matching sentences are:\n"; for (@matches) { print; print " => ", $sent{$_}, "\n"; }
Hope this helps ;0)
|
|---|