python - re.search() logically or two patterns in re.search() -
i have following string.
page load http://xxxx?roxy=www.yahoo.com&sendto=https://mywebsite?ent took 4001 ms (ne: 167 ms, se: 2509 ms, xe: 1325 ms)<br><br><br>topic: yahoo!! website website | mywebsite<br> or
page load http://xxxx?roxy=www.yahoo.com&sendto=https://mywebsite?ent took long (12343 ms ne: 167 ms, se: 2509 ms, xe: 1325 ms)<br><br><br>topic: yahoo!! website website | mywebsite<br> i want extract 4001 or 12343 above ent took 4001 ms or ent took long (12343 ms , assign variable
tt = int(re.search(r"\?ent\s*took\s*(\d+)",message).group(1)) this regex match first part , return me 4001.how logcially or expression r"\?ent\s*\took\s*too\s*long\s*\((\d+)" extract 12343 second part?
this 1 matches both patterns in 1 go , extracts desired number:
tt = int(re.search(r"\?ent took (too long \()?(?p<num>\d+)",message).group('num'))