On Tue, Nov 26, 2013 at 10:52:43AM -0500, Tom Limoncelli wrote: > How's this for a regular expression? It works on all the test cases > I've written so far. > > #! /usr/bin/python > > import sys > import re > > for x in sys.argv[1:]: > m = re.search(r'(.*)/*(.*)-(.*)-(.*?)\.(.*)(\.rpm)', x) > if m: > (path, name, version, release, platform, _) = m.groups() > path = path or '' > verrel = version + '-' + release > print "\t".join([path, name, verrel, version, release, platform]) > else: > sys.stderr.write('ERROR: Invalid name: %s\n' % x) > sys.exit(1) This won't work. Your path will include the name (first (.*) is eating all), your /* will be empty and the second (.*) will be empty too. This one will work I think: m = re.search(r'(.*?)([^/]+)-([^-/]+)-([^-/]+)\.([^\./]+)(\.rpm)', x) This can be shorter, but I linke more explicit expressions like [^\./]. You could make life easier by separating path and filename via the basename utility and then use a much simpler expression. Note: formally this does NOT guarantee the tags of the file, as you of course could rename a generated rpm file to whatever you want (and you can even ask rpmbuild to generate a different filename). Furthermore, purely theoretical (AFAIK) an rpm package could have a version or release containing a dash, but I've never seen one "in the wild" and probably rpmbuild prohibits building one. -- -- Jos Vos <jos@xxxxxx> -- X/OS Experts in Open Systems BV | Phone: +31 20 6938364 -- Amsterdam, The Netherlands | Fax: +31 20 6948204 _______________________________________________ Rpm-list mailing list Rpm-list@xxxxxxxxxxxxx http://lists.rpm.org/mailman/listinfo/rpm-list