in reply to Re: Optimizing regular expressions
in thread Optimizing regular expressions
The other thing that complicates this a bit is I'm not showing all the original text with the words highlighted in the final output, but rather just a few words on either side of the highlighted text. Like a google search shows. Thus, I also need to be careful not to print words twice when highlighted words are close together.
That is the reason I split the source text into an array of "swish" words and non swish words -- so I could easily mark words on either side of the matched word.
@words = split /([^$wordchars])/, $source_text;<p>
I use two arrays to track this now (instead of an array of arrays) as it was faster to avoid all the dereferencing.
Here's a specific question: The "problem" with the above code is that I still need to remove the leading and trailing ignore characters. So, that's an extra pattern match for every word - one time for the split, and then another to extract out a word from its ignore chars.
I tried to find an expression to use in the above spilt that would do this in one shot, but it was looking like a complicated expression that might be slower than doing two matches. But I never found a pattern that I could test.
I also wonder if using a repeating pattern with /g might be faster than my word-by-word checking. But then I'm back to the problem of how to print the words around the match.
Thanks again for your help.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Optimizing regular expressions
by japhy (Canon) on Jun 02, 2001 at 18:41 UTC | |
by moseley (Acolyte) on Jun 02, 2001 at 23:09 UTC | |
by japhy (Canon) on Jun 03, 2001 at 04:07 UTC | |
by moseley (Acolyte) on Jun 03, 2001 at 08:05 UTC | |
by japhy (Canon) on Jun 03, 2001 at 18:38 UTC | |
|