LPM: regexp question
llang at baywestpaper.com
llang at baywestpaper.com
Tue Dec 21 07:26:47 CST 1999
The following works for what you're trying to do, but it assumes (maybe
wrongly) that the words in your sentence are only separated by single
spaces. I guess you could remove multiple spaces easily enough before
running it through.
#======================================
$sent="This is a test of the first five words.";
@s=split(/ /,$sent);
pop(@s) while (@s>5);
if (join(" ", at s) =~ /\bis|are\b/) {
print "Do stuff here...";
}
#======================================
Loren Lang Phone: 606-734-0538 x326
Network Administrator Fax: 606-734-8210
Bay West Paper Corporation email: llang at baywestpaper.com
"There is no greater burden than great potential." - Charles Schultz
all righty then. what i'm trying to do is to determine if the words
"is" and "are" are one of the first five words in a sentence. the code
i'm using now looks like this: (yes, its ugly and newbie-ish)
my ($stu_foo,$stu_blah, at stu_search, at stu_refs,$stu_term);
$stu_term = $orig_Y;
@stu_search = ('is','are');
$theMsg =~ /(\w*)\s*(\w*)\s*(\w*)\s*(\w*)\s*(\w*).*?/;
@stu_refs = ($1,$2,$3,$4,$5);
foreach $stu_blah (@stu_refs) {
foreach $stu_foo (@stu_search) {
if ($stu_blah =~ /\b$stu_foo\b/ or $stu_blah =~ /\b$stu_term\b/) {
$theMsg = "<reply> $who: $theMsg";
goto OUT;
}
}
}
OUT:
anyway, is there a better way to do this? this seems awfully hackish to
me... thanks for your help all...
---------------------
Matt Cashner
sungo at earthling.net
---------------------
"In the battle between you and the world, bet on the world."
More information about the Lexington-pm
mailing list