Hi,
I would like to be able to extract the version number (nimbers and ,) from a string.
I can get the result but only if I use 1 type of delimeter
I have noticed that sometimes the delimeter changes so would like to have multiple delimeters options.
For example
Equally the first delimeter might be ,now 1:
For info the string is generated by
So I am getting in a bit of a pickle as I know I should be able to have multiple start delimeters and multiple end delimters,
I assume there must be a simpler way of doing this rather than a series of if statements searching to see what is the start and end delimeter in a string and then calling the correct re.search code.
Regex is really powerfull and a language unto itself but I've not got much spare capacity in my onbaord mental ROM anymore.
Any advice gratefully received.
Thanks and kind regards,
jB
I would like to be able to extract the version number (nimbers and ,) from a string.
I can get the result but only if I use 1 type of delimeter
I have noticed that sometimes the delimeter changes so would like to have multiple delimeters options.
For example
import re text = 'mawk/kinetic,now 1.3.4.20200120-3.1 amd64 [installed,automatic]' m = re.search(',now (.+?)-', text) print(m)
Output:<re.Match object; span=(12, 32), match=',now 1.3.4.20200120-'>
print(m.group(0)
Output:,now 1.3.4.20200120-
print(m.group(1))
Output:1.3.4.20200120
In this case m.group(0) contains the answer I need as the delimiter was - but sometimes it can be a + or : as the final delimeterEqually the first delimeter might be ,now 1:
For info the string is generated by
apt list --installed | grep -i mawk
(in this case)So I am getting in a bit of a pickle as I know I should be able to have multiple start delimeters and multiple end delimters,
I assume there must be a simpler way of doing this rather than a series of if statements searching to see what is the start and end delimeter in a string and then calling the correct re.search code.
Regex is really powerfull and a language unto itself but I've not got much spare capacity in my onbaord mental ROM anymore.
Any advice gratefully received.
Thanks and kind regards,
jB

buran write Apr-05-2023, 10:11 AM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.