import re from knock20 import text #print(text) texts = text.split('\n') pattern = re.compile('\|(.+?)\s=\s*(.+)') dic = {} for line in texts: r = re.search(pattern, line) if r: dic[r[1]] = r[2] print(dic)
import re import json from knock20 import text for line in text.split('\n'): if re.match(r'^\[\[Category:(.*?)*$', line): s = re.match(r'^\[\[Category:(.*?)(?:\|.*)*\]\]$', line) print(s.group(1))