0

How to search for version no python:

Build Host   : iox-lux-013 
Version      : 3.2.8.08I sample

I tried:

import re
p=re.compile("Version.*: (.*?) ")
list=p.findall(s)
for i in list:
        print i

works good
but not for:

Version      : 3.2.8.08I  

doesnt work :/

1
  • Works on my machine just fine. Show us your whole code. Where is s defined? Commented Mar 19, 2015 at 13:28

2 Answers 2

1

Use \S+ to match one or more non-space characters.

p = re.compile(r"Version\s*:\s*(\d+(?:\.\d+)*[A-Z]\b)")

\s* matches zero or more spaces , so you don't need to use .* before :

Example:

>>> s = '''Build Host   : iox-lux-013 
Version      : 3.2.8.08I sample
Version      : 3.2.8.08I'''
re.findall(r"Version\s*:\s*(\d+(?:\.\d+)*[A-Z]\b)", s)
['3.2.8.08I', '3.2.8.08I']
Sign up to request clarification or add additional context in comments.

1 Comment

Hi, If i give like this "Version : 3:2:8:08I ''' also it is extracting
0
import re

s = '''Build Host   : iox-lux-013
Version      : 3.2.8.08I sample
Version      : 3.2.8.08I '''

 f =  re.findall(r"Version\s+:( [0-9]+.[0-9]+.[0-9]+.[0-9]+[A-Z])(\s[A-Z])*", s)

print(f)

Use \S+ to match one or more non-space characters.

( [0-9]+.[0-9]+.[0-9]+.[0-9]+[A-Z]) this group will check for the version numbering. (\s[A-Z])* will check whether the string + space is availabl;e or not

* -> 0 or more

1 Comment

While this may answer the question it’s always a good idea to put some text in your answer to explain what you're doing. Read how to write a good answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.