[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: svn commit: rev 163 - trunk/subversion/tests/clients/cmdline/svntest

From: Branko Èibej <brane_at_xbc.nu>
Date: 2001-09-28 17:58:39 CEST

Bill Tutt wrote:

>A faster regular expression would be:
>"^(..)(.)([^\d]+)(\d+)\s+(.+)"
>In this case the the (\d+) would match 012345, and the enging wouldn't
>have to backtrack.
>
>Moral of the story:
>Always see if you can avoid using .* or .+ in the middle of a regular
>expression pattern, it degrades the matching performance of your regular
>expression.
>
>Secondary moral of the story:
>You're usually better off matching exactly what you're trying to match,
>and no more.
>Anything else can get you into trouble.
>
Right. So why not use:

    ^(..)(.)\s+(\*\s+)?(\d+)\s+(.+)$

You /know/ that the third column is an optional asterisk, so you might
as well say so explicitly. Then you can simply test for that with "$3 !=
undef", or whatever the Python equivalent is. And it make sense to
anchor the end of the regex; that doesn't change the way it matches, but
tells the reader that you really do want to match the whole line. That's
useful documentation, IMHO.

-- 
Brane �ibej   <brane_at_xbc.nu>            http://www.xbc.nu/brane/
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Sat Oct 21 14:36:42 2006

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.