Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6758919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:51:51+00:00 2026-05-26T13:51:51+00:00

I am trying to grab the version number from a string via python regex…

  • 0

I am trying to grab the version number from a string via python regex…

Given filename: facter-1.6.2.tar.gz

When, inside the loop:

import re
version = re.split('(.*\d\.\d\.\d)',sfile)
print version

How do I get the 1.6.2 bit into version

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T13:51:53+00:00Added an answer on May 26, 2026 at 1:51 pm

    Two logical problems:

    1) Since you want only the 1.6.2 portion, you don’t want to capture the .* part before the first \d, so it goes outside the parentheses.

    2) Since you only want to match the pattern in question and grab it, using re. split makes no sense. Instead, use re.match. This will give you a Match object, and you can use its .group() method to get the actual matched text. “group 0” is the entire matched pattern, “group 1” is what’s matched by the stuff inside the first set of parentheses, etc.

    >>> re.match('.*(\d\.\d\.\d)', 'factor-1.6.2.tar.gz').group(1)
    '1.6.2'
    

    Although as the other answer indicates, there’s actually no point in matching the .* part anyway, because we can instead search for the string that consists of only the part we want. This will look for the pattern anywhere within the string (matching expects it to be at the beginning). Since we don’t need parentheses to make the pattern work logically, and because we’re now going to use the entire matched portion, we no longer have any need for parentheses, either.

    >>> re.search('\d\.\d\.\d', 'factor-1.6.2.tar.gz').group(0)
    '1.6.2'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im trying to grab search items from twitter via PHP curl, process and update
I'm trying to grab data from a MySQL database. Approach 2 - apply/map style
Hi I am trying to grab a div from another website using JS. I
I am trying to grab stdout from a subprocess.Popen call and although I am
I'm trying to grab some JSON from Apple's iTunes JSON service. The request is
I am trying to grab all unique items from a DropDownList. Is there a
I'm trying to retrieve N number of items from an XML file using simpleXML
I need to get a particular version string from a file (call it version.lst)
Im trying to grab value from label checkbox:checked. I have created this function var
I'm trying to make a request using dojo.xhrGet to grab some XML data from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.