def fetch_data(document):
with open('data_file.pickle', 'rb') as fp:
datafile = pickle.load(fp)
matched_word = []
for data in datafile.splitlines():
job_regex = r'[^a-zA-Z]'+data+r'[^a-zA-Z]'
regular_expression = re.compile(job_regex, re.IGNORECASE)
regex_result = re.search(regular_expression, document)
if regex_result:
matched_word.append(data)
return matched_word
我想从datafile获取匹配数据到文档,但它返回空白列表。
答案 0 :(得分:0)
根据您提供的信息,我相信您应该使用字边界,\ b,而不是:
job_regex = r'\b'+data+r'\b'