From: Keith Gaughan Date: 2006-07-25T06:39:20+09:00 Subject: Re: Slow regular expressions On Tue, Jul 25, 2006 at 03:59:32AM +0900, S3 wrote: > logformat=/(\S+)\s+(\S+)\s+(.+)\s+\[([^\]]+)\]\s+"(\S+) +([^"]+) +[A-Za-z\/]*([0-9.]+)"\s+(\S+)\s+(\S+)\s+"([^"]+)"\s+"([^"]+)"/ A few other things: 1. What's with the all the '\s+'? All you need to do is match a space, so the regex becomes... rx = /^(\S+) (\S+) (\S+) \[([^\]])\] "(GET|POST|HEAD) (\S+) HTTP\/\d\.\d" \d{3} \d+/ As you can see, I've simplified a few other things, such as including anything that's constant, minimising all the places where you're matching whitespace to simple spaces. And I added the anchor at the beginning to match the start of the line, which is *very* important. K. -- Keith Gaughan - kmgaughan@eircom.net - http://talideon.com/ Catharsis is something I associate with pornography and crossword puzzles. -- Howard Chaykin