Ben is forgetting that CF 5 and earlier RegEx are greedy and his example will get a 
lot more than just from "Ben" to the period. It'll get from "Ben" to the last period 
on the page or string. This would work better in CF5 and earlier 
"Ben is [^.]*\.
Note that there's really just one type of comparison. Is the character a period or 
not. 
"Ben is [a-zA-Z ]*?\."
would work in MX. Note the ? after the asterisk. it says get all of a-z but only as 
many as needed to fulfill the requirements. Be stingy. But its still doing more 
comparisons. If the character an a? a b? a c? etc.


> 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
> 
> 
> 
______________________________________________________________________
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm
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