(Nov-14-2021, 09:11 PM)jehoshua Wrote: Just a small change to read the file into an array; works fine.Just a small correction you are not reading the file into a
array
(we call it list
in Python),when do
f.read()
read all into a string
,which is okay it will work fine.Let say don't want not want read all contend into memory,but do it line bye line and not close file bye using
with open
.Then it will be like this.
import re pattern = re.compile(r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+') with open('https.txt', 'r+') as f: for line in f: for match in pattern.finditer(line): print(match.group())