PY
py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# Created for GODOFPC's question:
# https://www.sololearn.com/Discuss/1365859
# How to take required Str from a Str in python
# For eg we are give a str in python like
# "2Spam + 3Eggs = 4Spameggs"
# Now how can I extract
# "2", "Spam", "3", "Eggs", "4", "Spameggs" ?
# So that I can assign them to different variables
import re
string = "2Spam + 3Eggs = 4Spameggs"
pattern = "[a-zA-Z]+|[0-9]+"
match = re.findall(pattern, string)
print(match)
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run