parsing a file name

C

CSUIDL PROGRAMMEr

I have a filename
cairo-2.3.4.src.rpm
Is there any way i can only get 2.3.4 from this file name
thanks
 
C

Chris Mellon

I have a filename
cairo-2.3.4.src.rpm
Is there any way i can only get 2.3.4 from this file name
thanks

I'm trying to think of a good reason to extract the version from the
filename instead of using RPM to get the real version from the
metadata and I can't come up with one.
 
P

Paul Boddie

Chris said:
I'm trying to think of a good reason to extract the version from the
filename instead of using RPM to get the real version from the
metadata and I can't come up with one.

The inquirer doesn't have any RPM handling tools installed/available or
is dealing with a lot of versioned filenames which might be a selection
of different, arbitrary formats.

Try harder! ;-)

Paul
 
C

Chris Mellon

The inquirer doesn't have any RPM handling tools installed/available or
is dealing with a lot of versioned filenames which might be a selection
of different, arbitrary formats.

Try harder! ;-)

Paul

Well, the answer to the first is "get some", so that's not a good
reason. And the second would mean that they asked a question on c.l.p
without giving all the background information on the task they were
doing, and we know that never happens.
 
R

Roberto Bonvallet

CSUIDL said:
I have a filename
cairo-2.3.4.src.rpm
Is there any way i can only get 2.3.4 from this file name
>>> a = "cairo-2.3.4.src.rpm"
>>> import re
>>> re.compile(r"\d+([.]\d+)*").search(a).group(0) '2.3.4'
>>> a.split("-")[-1][:-len(".src.rpm")] '2.3.4'
>>> ".".join(map(str, range(2, 5)))
'2.3.4'
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top