我使用Python来解析列表中的一些字符串。某些字符串可能只包含我要忽略的非字母数字字符,例如:
list = ['()', 'desk', 'apple', ':desk', '(house', ')', '(:', ')(', '(', ':(', '))']
for item in list:
if re.search(r'\W+', item):
list.remove(item)
# Ideal output
list = ['desk', 'apple', ':desk', '(house']
# Actual output
list = ['desk', 'apple', '(:', '(', '))']
这是我第一次尝试使用regex来解决这个问题,但并没有达到预期的效果。如何编写regex来忽略任何带有非字母数字字符的字符串?
目前没有回答
相关问题 更多 >
编程相关推荐