Oct-27-2017, 04:33 PM
(Oct-27-2017, 04:01 PM)heiner55 Wrote: My sample runs with Python 3.6 (not with Python 2.7).
Uninstall your Python 2.7 and install Python 3.6:
https://www.python.org/ftp/python/3.6.3/...-3.6.3.exe
As a new beginner you use Python 3.6.
This code runs with Python 3.6 or Python 2.7:
#!/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)))
Thanks mate, I've done that now..
But still getting an error, I get the following:
>>> import re
>>> pattern=re.compile(r'''tel:\s*?\+44\s*?(\d{10,10})''')
>>> 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 ", linenr, ": ", match[1])
Traceback (most recent call last):
File "<pyshell#11>", line 3, in <module>
match = re.search(pattern, line, re.X)
File "C:\Users\Ronnie\AppData\Local\Programs\Python\Python36-32\lib\re.py", line 182, in search
return _compile(pattern, flags).search(string)
File "C:\Users\Ronnie\AppData\Local\Programs\Python\Python36-32\lib\re.py", line 297, in _compile
"cannot process flags argument with a compiled pattern")
ValueError: cannot process flags argument with a compiled pattern
I was wondering how I can get rid of this?