20.如何写一个正则表达式,匹配每3 位就有一个逗号的数字?它必须匹配以
下数字:
'42'
'1,234'
'6,368,745'
但不会匹配:
'12,34,567' (逗号之间只有两位数字)
'1234' (缺少逗号)
import re
def test_test(one):
test = re.compile(r'^\d{1,3}(,\d{3})*$')
a = test.search(one)
if a != None:
print(a.group())
else:
print('None')
test_test('42')
test_test('1,234')
test_test('6,368,745')
test_test('6,368,45')
test_test('12,34,567')
test_test('1234')
21.如何写一个正则表达式,匹配姓Nakamoto 的完整姓名?你可以假定名字
总是出现在姓前面,是一个大写字母开头的单词。该正则表达式必须匹配:
'Satoshi Nakamoto'
'Alice Nakamoto'
'RoboCop Nakamoto'
但不匹配:
'satoshi Nakamoto'(名字没有大写首字母&#x