Python regex to remove all occurances of [Number] -


i'm looking regex statement in python remove occurances of [1] or [17] or [*] string. occurances follows * equals number:

[*] [ * ] [ *] [* ] 

currently have:

re.sub(r'\[*\]', '', origional_string) 

which raises invalid expression

example input string:

makeup of organisms.[10] in 1997, while working @ university of tennessee, pigliucci received theodosius dobzhansky prize,[11]  

expected output:

makeup of organisms. in 1997, while working @ university of tennessee, pigliucci received theodosius dobzhansky prize, 

i guess should work:

import re  origional_string = "makeup of organisms.[10] in 1997, while working @ university of tennessee, pigliucci received theodosius dobzhansky prize,[11]"  result = re.sub(r'\[ *[0-9]+ *\]', '', origional_string)  print(result) 

[0-9]+ matches 1 or more digits, while * matches spaces if any.

ideone demo


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -