¨ì©³¦b²Ö¤°»ò°Ú¡H wrote: >> How about >> my_string = "We the people of the United States, in order to form a >> more perfect union, establish justice, insure domestic >> tranquility,......" >> print (x for x in my_string.split(",") if "justice" in x).next() >> This isn't a regular expression, but it gives what you're looking for. >> THN > > Thanks a lot! I have never thought of that. > > But what if there's not only commas, but also periods and semicolons? I > want to find words between 2 near by punctuations. I think it would make > it difficult to use split instead of regular expression.
Reenter re. Use re.split(r"[.;\-,]", my_string) instead of my_string.split(","). Peter -- http://mail.python.org/mailman/listinfo/python-list