#!/bin/env python """Sentence matching regular expression This module shows a moderately complicated sentence matching regular expression. """ import re sent = re.compile(''' (?P # Match a sentence and label it (?: # Tokens are grouped together into a sentence (?:\w+|,)+ # Sentence tokens are words and/or commas \s* # Tokens are delimited by whitespace )+ # A sentence may have more than one token [.?!] # Sentences end with . ! or ? ) \s* # Allow trailing spaces after the sentence ''', re.VERBOSE) if __name__ == '__main__': import sys print "\n".join([s.group('sentence') \ for s in sent.finditer(' '.join(sys.argv[1:]))])