python regex statements on a single line -
I have a regex but I wanted to create them in a single expression without affecting output. Saves a list of code below, saves words and a list from a text.
one with import = [] open ('qwert.txt', 'r') as F: line f: res = re .findall (r '(?:? Pro [.] (\ W +)), line if res: a.extend (res) res = re.findall (r '(?: As (\ w +))', line if res: a.extend ( Res) res = re.findall (r '\ w + (? == \ w)', line) if res: a.extend (res) print
qwert.txt < Professor and professor and goodness = Mr. Prof. Texa Kell as a good person Kim Kim is right as Professor Jens John wins Nobel Prize in the form of Um won the prize for all cars that is good =
Output:
['every', 'kail', 'goodness',' How can tensa three regex stmts on one sin? How can three regex stmts on one sin? Gle line?
You can use the operator" | ", this allows you to find one or the other expression. res = re.findall (r '(?: Prof [.] (\ W +)). (?: As (\ w +)). (?: \ W + (? == \ w)), line)