题解 | #统计字符#
统计字符
http://www.nowcoder.com/practice/539054b4c33b4776bc350155f7abd8f5
正则表达式匹配
import re
while True:
try:
sentence = list(input().strip())
a, b, c, d = 0, 0, 0, 0
for item in sentence:
if re.match('[a-zA-Z]', item):
a += 1
elif item == ' ':
b += 1
elif re.match('[0-9]', item):
c += 1
elif re.match('[^a-zA-Z0-9]', item):
d += 1
print(a)
print(b)
print(c)
print(d)
except:
break
