i have problem with regex, i can't find a way get full line in doc with keyword.
i want to get result show"{"cid": "Ugfewffgikbsfewf3BAg", "text": "五男科永远不欢迎你", "time": "4 months ago", "author": "海wbeE", "votes": "1", "photo": "https://yt3.ggpht.com/a/AATXAJzjqGwefwef3Lrt5g4fhElmbFYC7o05S-ycUnlQ=s48-c-k-c0xffffffff-no-rj-mo"}" with keyword inside.
result same as linux commandline ' cat doc | grep keyword' please advice. thanks.
i want to get result show"{"cid": "Ugfewffgikbsfewf3BAg", "text": "五男科永远不欢迎你", "time": "4 months ago", "author": "海wbeE", "votes": "1", "photo": "https://yt3.ggpht.com/a/AATXAJzjqGwefwef3Lrt5g4fhElmbFYC7o05S-ycUnlQ=s48-c-k-c0xffffffff-no-rj-mo"}" with keyword inside.
result same as linux commandline ' cat doc | grep keyword' please advice. thanks.
import re doc = ''' {"cid": "Ugfewffgikbsfewf3BAg", "text": "洲男永远不欢迎你", "time": "4 months ago", "author": "海wbeE", "votes": "1", "photo": "https://yt3.ggpht.com/a/AATXAJzjqGwefwef3Lrt5g4fhElmbFYC7o05S-ycUnlQ=s48-c-k-c0xffffffff-no-rj-mo"}\n' {"cid": "Ugfewffgikbsfewf3BAg", "text": "五科永远不欢迎所有人", "time": "4 months ago", "author": "海wbeE", "votes": "1", "photo": "https://yt3.ggpht.com/a/AATXAJzjqGwefwef3Lrt5g4fhElmbFYC7o05S-ycUnlQ=s48-c-k-c0xffffffff-no-rj-mo"}\n' {"cid": "Ugfewffgikbsfewf3BAg", "text": "男科永远不欢迎你地", "time": "4 months ago", "author": "海wbeE", "votes": "1", "photo": "https://yt3.ggpht.com/a/AATXAJzjqGwefwef3Lrt5g4fhElmbFYC7o05S-ycUnlQ=s48-c-k-c0xffffffff-no-rj-mo"}\n' {"cid": "Ugfewffgikbsfewf3BAg", "text": "五洲永远不欢迎你们", "time": "4 months ago", "author": "海wbeE", "votes": "1", "photo": "https://yt3.ggpht.com/a/AATXAJzjqGwefwef3Lrt5g4fhElmbFYC7o05S-ycUnlQ=s48-c-k-c0xffffffff-no-rj-mo"}\n' ''' with open(doc, 'r', encoding='utf-8') as f: file=f.readlines() keywords = '欢迎' pattern = re.findall(r'[^,。]+[a-zA-Z0-9| \u4e00-\u9fa5]*{}[a-zA-Z0-9| \u4e00-\u9fa5]*'.format(keywords), str(file)) for match in pattern: print("\n") print(match)