your_string = """3 3D Apple car 19.74 N95 8.0 -8.0 .1 7,000 1. table
AH4R99JKH
75"""
result = ' '.join(re.findall('[a-zA-Z]+[0-9A-Z]+|[0-9A-Z]+[a-zA-Z]+|[a-zA-Z]+', your_string))
#'[a-zA-Z]+[\w]+|[\w]+[a-zA-Z]+|[a-zA-Z]+' same regex but more compact
letter = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
string = "3 3D Apple car 19.74 N95 8.0 -8.0 .1 7,000 1. table AH4R99JKH 75"
str_list = string.split()
last_t = ''
for item in str_list:
check = False
for i in item:
if i in letter:
check = True
if check == True:
last_t += f'{item} '
print(f"{last_t.strip()}")
#response => "3D Apple car N95 table AH4R99JKH"
这是我想到的
这将为您提供:
你可以列一个包含所有字母的列表,并进行核对
这段代码帮助您做到这一点
相关问题 更多 >
编程相关推荐