Python Forum
Please support regex for version number (digits and dots) from a string
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Please support regex for version number (digits and dots) from a string
#4
i usually avoid regex unless absolutely required. Here it is not because you can parse the string through process of elimination. And based on the fact that your regex string contains this in every file.

s = '''"SYS"."M_SYSTEM_OVERVIEW" ('System', 'Version', '', '2.00.050.00.1592305219 (fa/hana2sp05)')'''
version = s.split(',')[3].split(' ')[1].strip("'")
print(version)
outputs from elimination to final desired output. From why each index was selected from a certain split character
Output:
metulburr@metulburr:~$ python3 test2.py ['"SYS"."M_SYSTEM_OVERVIEW" (\'System\'', " 'Version'", " ''", " '2.00.050.00.1592305219 (fa/hana2sp05)')"] metulburr@metulburr:~$ python3 test2.py '2.00.050.00.1592305219 (fa/hana2sp05)') metulburr@metulburr:~$ python3 test2.py ['', "'2.00.050.00.1592305219", "(fa/hana2sp05)')"] metulburr@metulburr:~$ python3 test2.py '2.00.050.00.1592305219 metulburr@metulburr:~$ python3 test2.py 2.00.050.00.1592305219
The only thing that has to be added is obtaining the original string section from the file which could be different based on what the content of the file contains. You would have to find something unique in that string in comparison to parse out the rest of the file. Or for example if it has 1000 commas in the file, the index could be 98 instead of 3, etc.
Recommended Tutorials:
Reply


Messages In This Thread
RE: Please support regex for version number (digits and dots) from a string - by metulburr - Aug-15-2020, 12:08 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  parse/read from file seperated by dots giovanne 5 1,294 Jun-26-2023, 12:26 PM
Last Post: DeaD_EyE
Question Extracting Version Number from a String britesc 2 1,276 May-31-2023, 10:20 AM
Last Post: britesc
  Finding First Digits in String giddyhead 4 1,507 Aug-17-2022, 08:12 PM
Last Post: giddyhead
  TypeError: float() argument must be a string or a number, not 'list' Anldra12 2 5,159 Jul-01-2022, 01:23 PM
Last Post: deanhystad
Photo How can I use 2 digits format for all the number? plumberpy 6 2,521 Aug-09-2021, 02:16 PM
Last Post: plumberpy
  Regex: a string does not starts and ends with the same character Melcu54 5 2,607 Jul-04-2021, 07:51 PM
Last Post: Melcu54
  TypeError: int() argument must be a string, a bytes-like object or a number, not 'Non Anldra12 2 5,442 May-02-2021, 03:45 PM
Last Post: Anldra12
  cursor.execute: How to insert dynamic number in a string? stoeberhai 2 3,678 Mar-18-2021, 12:55 PM
Last Post: stoeberhai
  Regular expression: cannot find 1st number in a string Pavel_47 2 2,525 Jan-15-2021, 04:39 PM
Last Post: bowlofred
  Help getting a string out of regex matt_the_hall 4 2,418 Dec-02-2020, 01:49 AM
Last Post: matt_the_hall

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020