Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re(Amel): GREP/Regex - Locating Words in Sentences

by dsb (Chaplain)
on May 02, 2002 at 16:54 UTC ( [id://163595]=note: print w/replies, xml ) Need Help??


in reply to GREP/Regex - Locating Words in Sentences

You could extend this as necessary to accomodate a longer list of words to be tested.
$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"; }
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.

Hope this helps ;0)




Amel

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://163595]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2024-03-28 18:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found