Re: Needs help with Matching Logic

From: Paul Lalli (mritty_at_gmail.com)
Date: 07/20/04


Date: Tue, 20 Jul 2004 11:48:14 -0400

On Tue, 20 Jul 2004, Kishore wrote:

> I am comparitively a newbie in Perl.
> I am working a logic to display the snippets matched results of a
> 'keyword' from a text file just like google would do in the search
> results.
>
> I have the content of the text file in the variable $file_content.
> And I have the 'keyword' in $keyword.
>
> I need to get the string like google does when displaying the search
> results..
> When I match the $keyword in the $file_content, I want to also pull 5
> words before and 5 words after so I can show that snippet of the file
> where the matching of the keyword occurs.
>
> I searched in the google groups for a few days, but couldn't find
> anything to help me.
>
> I really appreciate any help I can get.

how about something like:

m/((?:\S+\s+){0,5})($keyword)((?:\s+\S+){0,5})/

Using that, $1 is the series of up to five words before the match, $2 is
the match, and $3 is the series of up to five words after the match.

It'd probably have to be tweaked a bit to get exactly what you want, but
it should at least give you a starting point.

Paul Lalli



Relevant Pages

  • Re: About keyword
    ... > problem is i want to display the google ads for particular keyword. ...
    (microsoft.public.dotnet.faqs)
  • Re: About keyword
    ... >> problem is i want to display the google ads for particular keyword. ...
    (microsoft.public.dotnet.faqs)
  • Needs help with Matching Logic
    ... I am comparitively a newbie in Perl. ... I am working a logic to display the snippets matched results of a ... And I have the 'keyword' in $keyword. ... I need to get the string like google does when displaying the search ...
    (comp.lang.perl.misc)
  • Re: Any Dutch people in this group?
    ... Google *does* use the description for displaying purposes. ... > page again) would you recommend using the main keyword 'maleisie'? ... Also, don't focus on one main keyword, ... PHP: similar to above, .php, but .html can be parsed as PHP ...
    (alt.internet.search-engines)
  • Re: Pocket pcs
    ... (iPhone is out of luck too) ... use Google Maps or WLS for WinMo? ... Google won't display period on my ppcs. ... 99 of them won't display properly. ...
    (microsoft.public.pocketpc)