Re: Speed comparison of regex versus index, lc, and / /i



Ben Bullock <benkasminbullock@xxxxxxxxx> wrote:
In a recent discussion on this newsgroup, it was mentioned that
"index" is better for matching fixed strings than using regular
expressions.

Yes, it is. If using regex to match fixed strings, you need to worry
about special characters or syntax errors in the regex, like the problem
with the literal string like "[l-c]" which we recently witnessed here.

Coincidentally I've recently been setting up a search
system for a fairly large volume (about 30 megabytes) of text files,
and as a first approximation for the search system I made a simple
routine to open each file and search for the string in the file using
"index".

As a test of the proposition that index is better than regexes,

"Better" is a much bigger issue than merely faster.

....


So my conclusion is that "index" isn't necessary and one can always
use regexes

True. On the other hand, Perl isn't necessary and one can always use other
languages. Computers aren't necessary and one can always use paper and
pencil. Where is this headed?

And of course, if you are interested in where the string matches (i.e. the
return value of index, and not just whether or not it is -1) then it is
simpler to get it from index than from a regex.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
.