当前位置:网站首页>Re regular matching findall (. +?) Match any content that conforms to a certain format (regular matching catch bullet screen)

Re regular matching findall (. +?) Match any content that conforms to a certain format (regular matching catch bullet screen)

2022-01-15 02:10:45 Review of the white speed Dragon King

demand :
A that cannot be resolved successfully json txt, Only through re To match the corresponding content

What I'm looking for is :

 Insert picture description here
Here's what

Code :

import json
import re


def get_danmu(fname):
    with open(fname, 'r', encoding = 'utf-8') as f:
        data = f.read()
    res = re.findall(r'\\\"content\\\":\\\"(.+?)\\\"', data)
    with open("output1.txt", 'w', encoding = 'utf-8') as f:
        for each in res:
            f.write(each + "\n")


if __name__ == '__main__':
    get_danmu("danmu1.txt")

Output :
 Insert picture description here
summary :
1.\ and “ To escape meaning
2.(.+?) Greedy matching

版权声明
本文为[Review of the white speed Dragon King]所创,转载请带上原文链接,感谢
https://chowdera.com/2021/12/202112122241256595.html

随机推荐