in reply to Speeding up a large regex match pattern

As a general proposition, avoiding using unnecessary captures is a Good Thing.

Also as a general proposition, optimisation should be avoided until it becomes obvious that it is unavoidable.

use re 'debug' can tell you a lot about what's going on -- getting a trace of what happens on some real data can be quite instructive. YAPE::Regex::Explain is reputed to be useful, but it does look a little old -- other monks may be able to advise.

One thing that can really slow down regex is back-tracking. The more specific the matching elements, the less opportunity you give for backtracking, the better. Note that a floating start to a regex is an excellent way of triggering a lot of backtracking !

Replies are listed 'Best First'.
Re^2: Speeding up a large regex match pattern
by wossname (Novice) on Feb 04, 2009 at 21:35 UTC
    Thanks for the fast replies everyone!

    Yeah I realise this METAR thing has been done many times and in many ways. I am merely using it as a means to test my knowledge of regular expressions.

    I have no real use for a METAR processor script but the huge amount of freely available data combined with the significant complexity of the protocol make it an ideal case study for learning the ropes, as it were.

    I'm interested in the links that you kindly posted though. I think I'll probably finish my "hard way" METAR script first and then I'll try it again using a proper parser. That way I think I'll get the benefit from both coding the logic manually and also taking a more high level approach.

    Thanks again.

    Wosser.

    I'm so glad I found perlmonks.org, this place is a far more substantial knowledge base than anywhere else I've found.