From here
https://regex101.com/r/Cy4Bua/2
you can see that to match the version I have 3 capturing group. Could I make it to only 1 which is the "group 1"?
Asked
Active
Viewed 43 times
-2

william007
- 17,375
- 25
- 118
- 194
-
1What is the expected output you need to get in Python and what are the requirements? For now, it seems you may just use `\d[\d.]*` or `\d+(?:\.\d+)*` – Wiktor Stribiżew Sep 29 '17 at 10:04
-
expected output is Group1 only (full version number matched) e.g., "hello this is version 1.2.33.4" matched “1.2.33.4” – william007 Sep 29 '17 at 10:11
-
You hardly ever need to wrap the whole pattern with a capturing group - are you using it in `re.split`? Please explain what you are doing if my suggestions above do not work for you ([demo 1](https://regex101.com/r/iQCoPs/1), [demo 2](https://regex101.com/r/xKDuFz/1)). Please also show the relevant Python code. – Wiktor Stribiżew Sep 29 '17 at 10:14
3 Answers
1
In your simple case it's enough to apply re.search()
function:
import re
s = 'hello this is version 1.2.33.4'
v = re.search(r'\d+(?:\.\d+)*', s).group()
print(v)
The output:
1.2.33.4

RomanPerekhrest
- 88,541
- 4
- 65
- 105