我正在寻找python中的regex语句,它将从字符串中删除所有出现的[1]或[17]或基本上[*]。发生情况如下,其中*等于某个数:
[*]
[ * ]
[ *]
[* ]
目前我有:
re.sub(r'\[*\]', '', origional_string)
引发invalid expression
输入字符串示例:
makeup of organisms.[10] In 1997, while working at the University of Tennessee, Pigliucci received the Theodosius Dobzhansky Prize,[11]
预期产量:
makeup of organisms. In 1997, while working at the University of Tennessee, Pigliucci received the Theodosius Dobzhansky Prize,
我想这样应该行得通:
[0-9]+
匹配一个或多个数字,而*
匹配空格(如果有)。你知道吗ideone demo
\d
表示正则表达式中的数字。我还在这里的数字周围添加了选项\s
。你知道吗相关问题 更多 >
编程相关推荐