regex - python reg exp: how to delete a field delimited by [ and ] from a string -
i have file , every line looks this:
2013-04-23 16:04:12.276 bla[16878:950f] 'asdf' : 0, 'asds': 0, 'adf': 0
i need replace part bla[16878:950f]
,
.
note text bla
same, text within [
and ]
different , can have different length.
what need @ end is:
2013-04-23 16:04:12.276, 'asdf' : 0, 'asds': 0, 'adf': 0
any ideas? i'm bad @ regular expressions, think way.
thanks
>>> import re >>> line = "2013-04-23 16:04:12.276 bla[16878:950f] 'asdf' : 0, 'asds': 0, 'adf': 0" >>> re.sub(r'bla\[[^\]]+\]', ',', line) "2013-04-23 16:04:12.276 , 'asdf' : 0, 'asds': 0, 'adf': 0"
i think want replace spacebla[16878:950f]
though: add space in if wish