[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Regexp to parse "Version:" fields



On Wed, Jun 21, 2006 at 01:56:21PM +0200, Christoph Haas wrote:
>for mentors.debian.net I would like to find a perfect (TM) regular
>expression to split the "Version:" line of a control file into:
>
> - epoch
> - upstream version
> - Debian package revision
>
>My current attempt is:
>
>   ^(?:(\d+):)?(\d[\w\.\+-:]*?)(?:-(.+))?$

If you really want a single regex you could use:

    ^(?:([^:]+):)?(.*?)(?:-([^-]+))?$

My inclination however would be to use multiple steps to split the
version:

    my $epoch = '';
    my $debver = '';
    for ($version)
    {
	$epoch  = $1 if s/^([^:]+)://;
	$debver = $1 if s/-([^-]+)$//;
    }

--bod



Reply to: