Removing time stamp and jump to a new line

I have a text like this :
[14:38] kkkk[15:06] check [15:07] gffgfgfgfgfgfgfgfgfgfgfgf [15:08] dasdsadsadsdsds [15:09] tessssttt
I want to replace the time in the brackets with - and that each line starting with the time stamp will be separated and will be moved to a new line.
So the final output will be something like this :

  • kkkk
  • checkddssfsf
  • gffgfgfgfgfgfgfgfgfgfgfgf
  • dasdsadsadsdsds
  • tessssttt ssaf dsfdsf scfc
    For replacing the time stamp i have this line ‘mod_string = re.sub(r’([^)]*)’ ,’’,orig_string)’
    How should i proceed and which action should be committed first?

share your current python code

What is your problem? You got two clear goals, you can use regular expressions.

Maybe it will be more clear now , i have this code :

import re
orig_string = "[14:38] kkkk[15:06] checkccc [15:07] "
mod_string = re.sub(r'\([^)]*\)','',orig_string)

Now if i run it, the time will be removed but i will have a big string in one line : " kkkk checkccc "
I actually wanted to separate each string line by line but instead of something like this :
[14:38] kkkk
[15:06] check
[15:07] gffgfgfgfgfgfgfgfgfgfgfgf
[15:08] dasdsadsadsdsds
[15:09] tessssttt
it should look like this :

  • kkkk
  • check
  • gffgfgfgfgfgfgfgfgfgfgfgf
  • dasdsadsadsdsds
  • tessssttt

try this

orig_string = “[14:38] kkkk[15:06]”
mod_string = orig_string. translate ({ord(c): " " for c in “!@#$%^&*(){};:,./<>?|`~-=_+”})

re.sub() replaces the pattern of the first argument with the string in the second - ofcourse if you tell it to replace it with an empty string, you will just delete it.

However according to your task, you want to replace it with [-], so why don’t you do that?
Then do you want to save the result as a string and add newlines, or as an array and split the string?

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.