假设我有很长的文字。从下面的文字我只需要抽象的部分。如何避免{{ }}
之间的文字。谢谢
`
{{ Info extra text}}
{{Infobox film
| name = Papori
| released = 1986
| runtime = 144 minutes
| country = Assam, {{IND}}
| budget = [[a]]
| followed by = free
}}
Albert Einstein ( /'ælb?rt 'a?nsta?n/; German: ['alb?t 'a?n?ta?n] ( listen); 14 March 1879 – 18 April 1955)
was a German-born theoretical physicist who developed the theory of general relativity, effecting a
revolution in physics. For this achievement, Einstein is often regarded as the father of modern physics
and one of the most prolific intellects in human history.`
输出:
Albert Einstein ( /'ælb?rt 'a?nsta?n/; German: ['alb?t 'a?n?ta?n] ( listen); 14 March 1879 – 18 April 1955)
was a German-born theoretical physicist who developed the theory of general relativity, effecting a
revolution in physics. For this achievement, Einstein is often regarded as the father of modern physics
and one of the most prolific intellects in human history.
答案 0 :(得分:1)
我做了什么:
>>> text
"{{ Info extra text}}\n{{Infobox film\n| name = Papori\n| released = 1986\n| runtime = 144 minutes\n| country = Assam, {{IND}}\n| budget = [[a]]\n| followed by = free\n}}\nAlbert Einstein ( /'ælb?rt 'a?nsta?n/; German: ['alb?t 'a?n?ta?n] ( listen); 14 March 1879 – 18 April 1955)\n was a German-born theoretical physicist who developed the theory of general relativity, effecting a\n revolution in physics. For this achievement, Einstein is often regarded as the father of modern physics \n and one of the most prolific intellects in human history.`"
>>> re.sub(r"\{\{[\w\W\n\s]*\}\}", "", text)
"\nAlbert Einstein ( /'ælb?rt 'a?nsta?n/; German: ['alb?t 'a?n?ta?n] ( listen); 14 March 1879 – 18 April 1955)\n was a German-born theoretical physicist who developed the theory of general relativity, effecting a\n revolution in physics. For this achievement, Einstein is often regarded as the father of modern physics \n and one of the most prolific intellects in human history.`"
编辑:巴特的评论是正确的。
可能会考虑这个替代方案:
>>> re.sub(r"\{\{[^\}]*\}\}", "", "{{a\n oaheduh}} b {{c}} d")
' b d'