in reply to Swish module (was Re: Re: Optimizing regular expressions)
in thread Optimizing regular expressions
$find = Swish->new( "'", # ignore beginning "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'", "'", # ignore ending 'breath every', 5, # words to highlight BEFORE 5, # words to highlight AFTER ); de>
With a call-back function of:
$find->stream(\*DATA, sub { " ... $_[1]<b>$_[2]</b>$_[3] ..." }); while (my $t = $find->match) { print "[[$t]]\n" }
And I get this result:
keywords are: <breath> <every> [[ ... With <b>every</b> form you come You surprise ...]] [[ ... me, hypnotize me << shouldn't be a break here With <b>every</b> ...]] [[ ... <b>breath</b> I take << or here You're depriving, suffocating ...]] [[, choking << here's the rest of the text? Now the time has come when I tell myself There's nothing more I can take Then you show me Does it matter right now If I'm already numb That's what you do to control me ]]
It's tough to realize when words match near each other and to then print out a complete line of text.
In other words, I'm looking for this output:
With <b>every</b> form you come ... hypnotize me With <b>every</b> <b>breath</b> I take You're ...
So the code realizes that "every" and "breath" are near each other so not to print out words on either side twice.
Well, I'll have to work through it on Monday.
Thanks,
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Swish module (was Re: Re: Optimizing regular expressions)
by japhy (Canon) on Jun 03, 2001 at 18:38 UTC | |
by Anonymous Monk on Jun 10, 2001 at 17:25 UTC |