Regex not matching \t\n\r\f\v in Python
Question: I have a list of a strings:

    
    
    content = ['***************************************\n\t', 'ADVENTURE', '*', 'Solving', 'it', 'in', 'easy', 'steps', '*\n\t', '*\t\t\t\t', '*\n\t', '*\t\t\t\t', '*\n\t', '***************************************\n\t\t', 'FROM:', 'THE', 'ROM', 'DR.', 'CALL', 'HER']
    

In which I'm trying to remove anything that ends with a non-alphanumeric
character like \t \n \v and so on.

I have the following code:

    
    
    import re
    
    for each in content:
    m = re.match('.*[\t\n\r\f\v]+',each) 
    if m:
        content.remove(each)
    

But the output is still giving me strings with \n or \t. Any ideas?


Answer: You dont need `regex` , use `str.strip()` and `set` (**if you have not
duplicated elements in your list (or you dont want duplicates) because`set`
remove duplicates** ), first you `strip` all the element of `content` list
(removing whitspaces at leading and trailing of the string ) and then use a
logic and `&` that works between tow `set` between new striped list and first
list to chose elements that are in both (elements that `strip()` function
doesn't change them so those are in both list) :

    
    
    >>> new=[i.strip() for i in content]
    >>> set(content) & set(new) 
    set(['*', 'in', 'ROM', 'HER', 'Solving', 'it', 'CALL', 'ADVENTURE', 'easy', 'DR.', 'steps', 'THE', 'FROM:'])
    

