PY
py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
'''
https://www.sololearn.com/Discuss/3257875/?ref=app
'''
#what is allowed and what is not allowed
#digits space digits #allowed
#digits comma digits #allowed
# rest all not allowed
import re
#pattern = r"/^\d+((,\d+)*|( \d+)*)$/gm"
pattern = r"^\d+((,\d+)*|( \d+)*)$"
#pattern = r"^((,\d+)*|( \d+)*)$"
def validateString(str):
if re.match(pattern,str):
return True
else:
return False
return False
values = ["123","123 11","23 02 11","1,12,22","22,09","","12,23 1"]
for elem in values:
print(elem,validateString(elem),sep="-->")
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run