Maybe this helps: https://docs.python.org/3.6/library/re.html
here is some text "tel:+44 1234567890" hers is some text
tel: +44 1234567890 text text
text tel text tel: +441234567890 text
tel:+441234567890
#!/usr/bin/python3 import re pattern = r""" tel: # tel: \s*? # maybe some spaces \+44 # +44 \s*? # maybe some spaces (\d{10,10}) # 10 digits """ with open ('phone_log.txt') as in_file: for linenr, line in enumerate(in_file): match = re.search(pattern, line, re.X) if match: print("Line %d: %s" % (linenr, match.group(1)))phone_log.txt:
here is some text "tel:+44 1234567890" hers is some text
tel: +44 1234567890 text text
text tel text tel: +441234567890 text
tel:+441234567890
Output:Line 0: 1234567890
Line 1: 1234567890
Line 2: 1234567890
Line 3: 1234567890