I'm using Python to parse some strings in a list. Some of the strings may only contain non-alphanumeric characters which I'd like to ignore, like this:
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', '(:', '(', '))']
That's my first attempt at the regex for this problem, but it's not really having the desired effect. How would I write a regex to ignore any strings with non-alphanumeric characters?