good chemistry is complicated,
and a little bit messy -LW
Matching simple patterns - is there a faster way?by mrguy123 (Hermit)
|on Aug 09, 2012 at 06:41 UTC||Need Help??|
mrguy123 has asked for the
wisdom of the Perl Monks concerning the following question:
Hi Monks, as mentioned before, I am working on a project that checks many thousands of links. One of the tests I do is try to match a very simple pattern to the HTML page fetched by the link. A very simple example (taken from the Alpaca book) to demonstrate:
My question is, if the pattern is indeed only letters like the example above (no wildcards, character classes etc.), is regex matching the fastest way to go? Maybe grep matching or substring matching would be quicker?
Or is the regex engine smart enough to do faster matching for simple patterns?
Since I am checking 1000s of HTML pages and in some cases I want to match quite a few patterns anything that could make this run a bit faster would really help me out
Also I'm quite curious about the answer to this question
UPDATE: After trying kcott's helpful suggestion, I get this results (code below in one of my answers), so it seems regex is still faster:
Everybody seems to think I'm lazy
I don't mind, I think they're crazy