[buug] regex question

Nick Moffitt nick at zork.net
Wed Apr 30 15:56:24 PDT 2003


begin  Aaron T Porter  quotation:
> On Wed, Apr 30, 2003 at 01:56:24PM -0700, Nick Moffitt wrote:
> 
> > > 	($id) = $_ =~ m"UserID=(.*)&";
> > 
> > 	That's nice, but it does a lot of backtracking from the end to
> > figure out which & is the terminating symbol.  It's much more
> > efficient to use some variant of "[^&]+" instead of ".*".  The match
> > then stops at the first & it sees instead of hoping for a later one in
> > the string.
> 
> 	My perl code is rarely (if ever) described as efficient :)

	Well, consider also what your code would do in the event of:

aaaaaaaaaaUserID=374743&bbbbbbbbbb&bbbbbbb

You'd get "374743&bbbbbbbbbb" on account of the greediness of *

-- 

end



More information about the buug mailing list