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 590799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:34:03+00:00 2026-05-13T15:34:03+00:00

I have a string which has a version number. I want to read the

  • 0

I have a string which has a version number. I want to read the version number from this code so I can compare it with other code I am using. I have code done below but cannot get it working, can anyone see the problem?

print results

    r = re.compile(r'(version\s*\s*)(\S+)') 

    for l in results: 
        m1 = r.match(l) 
        if m1: 
            ID=map(int,m1.group(2).split("."))  
            l = r.sub(r'\g<1>' + '.'.join(['%s' % (v) for v in ID]), l)
            print ID

the results variable is:

Name Info Type Call version 1.0.40.437 Fri Oct  2 10:54:35 BST 2009

I have it done this way as I need the numbers in the ID separated into groups as I need to compare the 3rd number in the ID to the third number in the ID in another file.

The below answers are useful, but the way I had it would read a file and take all the numbers out and put them into a list so all I would have to do is compare the two numbers of the list. Sorry if the question was not clear but I don’t want the version number to be a string.

Okay I made a couple of changes to the code that was answered below. The code is as follows:

    version = re.compile('version\s+([\d.]+)\s+') 
    ID = version.search(results) 
    if ID: 
        value = ID.group(1).split('.')[2]

    self.assertEqual(BUILD_ID[2], int(value))

This does not create the list that I wanted but it allows me to compare the 2 values.

Thanks for all the help.

  • 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-13T15:34:04+00:00Added an answer on May 13, 2026 at 3:34 pm

    Why regexp? I should use split(‘ ‘) and use value next to ‘version’, or simplier:

    print results.split(' ')[5]
    

    If you must use regexp then try:

    rx = re.compile('version\s+([\d.]+)\s+')
    rxx = rx.search(results)
    if rxx:
        print rxx.group(1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string which has an xml inside. I want to write this
I have a JSON string (external file) which has an element which can either
I have a class which has two HashSet<String> collections as private members. Other classes
I have a string which has the below content String msg = The variables
i have a string which has the following format (3,1,Mayer,Jack). I need all 4
I have a bean of type string[] which has two or more values. I
I have a Person class which has a String collection of aliases representing additional
I have a table in db2 which has the following fields int xyz; string
I have a model for assessment criteria which has a :label field containing string
I have a function written in C# which has one parameter type as Dictionary<string

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.