BTW, thanks for reminding me I have to write up a section on optimal RegEx. 

Michael Dinowitz
Master of the House of Fusion
http://www.houseoffusion.com
----- Original Message ----- 
From: "Ben Doom" <[EMAIL PROTECTED]>
To: "CF-Talk" <[EMAIL PROTECTED]>
Sent: Wednesday, July 10, 2002 9:36 AM
Subject: RE: Regular Expressions/Speed


> Disclaimer:  I learned on Perl, so every once in a while, my syntax gets
> garbled between Perl and CF.  Either forgive me or ignore me.
> 
> There are one or two things you can do to optimize regexps in general.
> 
> First, maximize the length of any mandatory fixed string.  That is, if you
> know a substring will always be present in the same position, put that
> substring in your regexp.
> 
> So, if you are trying to match all the following:
> Ben is cool.
> Ben is smart.
> Ben is pretty decent at regular expressions, having come from a Perl
> background.
> You would use something like
> "Ben is [a-zA-Z ]*\."
> to use "Ben is " and the trailing period to limit the length of string the
> parser has to search for the dynamic bits.
> 
> Second, think about the number of comparisons to make.  Typically, the fewer
> comparisons the parser makes to match properly, the faster it runs.
> 
> So, to validate that something looks like an HTML tag, we could look for:
> '<[a-zA-Z[:space:]_="]>'
> Or we could look for
> '<[^<>]>'
> Which, with every parser I've ever seen, will run slightly faster.
> 
> 
> The only other thing I'd say is that when I write regexps, I don't think too
> much about speed until I'm sure that I've got one that finds exactly what I
> want, only what I want, and always captures what I want.  To me, accuracy is
> more important that saving cycles.
> 
> 
> 
>   --Ben Doom
>     Programmer & General Lackey
>     Moonbow Software
> 
> 
> 
______________________________________________________________________
This list and all House of Fusion resources hosted by CFHosting.com. The place for 
dependable ColdFusion Hosting.
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to