H
H
hagnoherze2021-09-06 15:03:43
Regular Expressions
hagnoherze, 2021-09-06 15:03:43

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>

Between </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

Tried like this:
Elapsed\sTime:\D+(.+?)<\/font>[\n]*.Last\sCalled\sNumber:\D+(\d{5,})@gw0<\/font>\D+(\d{5,})<\/font>

Does not work.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
H
hagnoherze, 2021-09-07
@hagnoherze

Elapsed\sTime.*?<font.*?>(.*?)<\/font>(.|\r|\n)+Last\sCalled\sNumber:.*<font.*>(.*?)\@.*?<\/font>.*?<font.*?>(.*?)<\/font>(.|\r|\n)

V
Viktor Taran, 2021-09-06
@shambler81

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.

K
Kudis, 2021-09-06
@kudis

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))

Conclusion:
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 question

Ask a Question

731 491 924 answers to any question