Answer the question
In order to leave comments, you need to log in
How to make a regular schedule?
There is a text
Elapsed Time:</td><td><font color="darkblue">16 days and 12:42:31</font><>
<>
<><>
<>
<>7gt757tLast Called Number:</td><td>
<font color="darkblue">[email protected]</font>
</td><td>Last Caller Number:</td>
<td><font color="darkblue">876868856454</font>
</font> и Last Called Number:
can be any text and any number of line breaks (/n). Expected Result:16 days and 12:42:31
67678799989
876868856454
Elapsed\sTime:\D+(.+?)<\/font>[\n]*.Last\sCalled\sNumber:\D+(\d{5,})@gw0<\/font>\D+(\d{5,})<\/font>
Answer the question
In order to leave comments, you need to log in
Elapsed\sTime.*?<font.*?>(.*?)<\/font>(.|\r|\n)+Last\sCalled\sNumber:.*<font.*>(.*?)\@.*?<\/font>.*?<font.*?>(.*?)<\/font>(.|\r|\n)
https://regex101.com/r/aWofwq/1
or an even more genocidal version
https://regex101.com/r/5URmVz/1
so I switch the syntax and immediately see what the problem is, is it really so difficult.
Everything should work:
import re
str = '''
<>
<><>
<>
<>7gt757tLast Called Number:</td><td>
<>
<><>
<>
<>7gt757tLast Called Number:</td><td>
Elapsed Time:</td><td><font color="darkblue">16 days and 12:42:31</font><>
<>
<><>
<>
<>7gt757tLast Called Number:</td><td>
<font color="darkblue">[email protected]</font>
</td><td>Last Caller Number:</td>
<td><font color="darkblue">876868856454</font>
<>
<><>
<>
<>7gt757tLast Called Number:</td><td>
<>
<><>
<>
'''
result = re.findall(r'<font color=\"darkblue\">(.*?)</font>', str)
print('\n'.join(result))
b4c598beb13c:python -u /opt/project/habr_regex.py
16 days and 12:42:31
[email protected]
876868856454
Process finished with exit code 0
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question