Answer the question
In order to leave comments, you need to log in
How to find a word in a string by criteria?
There is a line: "new version - version1". How to find the word version1 by: only English letters, by the presence of numbers, by the number of characters - in this case there are 7 of them. And all these 3 conditions are mandatory.
Those. there can be several lines, but a word must be found from them according to the criteria
Examples:
"new version yesterday - version1" | Finds: version1
"new version today is version2" | Finds: version2
"new version tomorrow - version3". | Finds: version3
Answer the question
In order to leave comments, you need to log in
Use regular expressions:
import re
s = "новая версия вчера - version1"
r = re.search(r'[a-zA-Z]{7}\d', s)
print(r.group())
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question