Converting a String to a List of Words?

Try this: import re mystr=”This is a string, with words!” wordList = re.sub(“[^\w]”, ” “, mystr).split() How it works: From the docs : re.sub(pattern, repl, string, count=0, flags=0) Return the string obtained by replacing the leftmost non-overlapping occurrences of pattern in string by the replacement repl. If the pattern isn’t found, string is returned unchanged. … Read more

Can grep show only words that match search pattern?

Try grep -o: grep -oh “\w*th\w*” * Edit: matching from Phil’s comment. From the docs: -h, –no-filename Suppress the prefixing of file names on output. This is the default when there is only one file (or only standard input) to search. -o, –only-matching Print only the matched (non-empty) parts of a matching line, with each … Read more