python - How to match info from a string -


I have a string whose version number I want to read the version number from this code so that I compare it with the second code I can use what I am using. I have been coded down but this can not work, can anyone see the problem?

  Print result for r = re.compile (r '(version \ s * \ s *) (\ S +)') In the result: M1 = R.Match (L) If the M1: ID = map (int, M1group (2) .split (".")) For the id in L = r.sub (r '\ g <1 & gt; id) (['% ' S '% (v)), L) Print ID  

is the result variable:

  name information type call version 1.0.40.437 Venus 2 October 10: 54:35 bst 200  

I have done this in this way because I need numbers in the ID groups to enter the id number of ID In the second file and need to be compared to another number.

The answers given below are useful, but the way I was, read a file and put all the numbers out and put them in a list so that everyone would have to compare two numbers in the list. Sorry if the question was not clear, but I do not want the version number string to be.

OK I made two changes in the code below. The code is as follows:

  version = re.compile ('version \ s + ([\ d.] +) \ S +') ID = version.search (result) if id: value = ID.group (1) .split ('.') [2] self.assertEqual (BUILD_ID [2], int (value))  

this list does not make it , But it allows me to compare 2 values.

Thanks for all help.

Why regexp? I should use split ('') and use the value next to 'version', or simple:

  print result. Split ('') [5]  

If you want to use regexp then try:

  rx = re.compile ('version \ s + ([\.] +) \ S + ') Rxx = rx.search (result) if rxx: print rxx.group (1)  

Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -