Simple Filter Python script for Text
Question: I am trying to create what must be a simple filter function which runs a regex
against a text file and returns all words containing that particular regex.

so for example if i wanted to find all words that contained "abc", and I had
the list: `abcde`, `bce`, `xyz` and `zyxabc` the script would return `abcde`
and `zyxabc`.

I have a script below however I am not sure if it is just the regex I am
failing at or not. it just returns abc twice rather than the full word.
thanks.

    
    
    import re
    
    text = open("test.txt", "r")
    regex = re.compile(r'(abc)')
    
    for line in text:
        target = regex.findall(line)
        for word in target:
            print word
    


Answer: I think you dont need regex for such task you can simply `split` your lines to
create a list of words then loop over your words list and use `in` operator :

    
    
     with open("test.txt") as f :
         for line in f:
             for w in line.split():
                  if 'abc' in w :
                       print w 
    

