Hello, happy [4th of July]. I love the [[firework]]
我有这些文字:
text = {{Hey, how are you.}} I've watched John Mulaney all night. [[Category: Comedy]] [[Image: John Mulaney]]
我正在尝试删除{{嘿,你好。}}、[[类别:喜剧]]和[[图片:约翰穆拉尼]]。这是我迄今为止尝试过的,但似乎不起作用:
hey_how_are_you = re.compile('\{\{.*\}\}')
category = re.compile('\[\[Category:.*?\]\]')
image = re.compile('\[\[Image:.*?\]\]')
text = hey_how_are_you.sub('', text)
text = category.sub('', text)
text = image.sub('', text)
你在用一种很奇怪的方式去做那件事。尝试阅读有关正则表达式文档的更多信息。请尝试以下操作:
请注意,输出字符串的前面还有一个空格,后面还有2个空格。我让你想想怎么做。有帮助吗?你知道吗
请看一下关于如何使用RE排除除[7月4日]以外的所有内容的文档。你知道吗
@Duy,看下面两个例子。你知道吗
例2
下面的代码是您的第二个输入文本。你知道吗
例3
相关问题 更多 >
编程相关推荐