+ 2

Specific characters removal

[15.7., 20:32] Srki: Смета [15.7., 20:32] Srki: Покрива даску [15.7., 20:32] Srki: Ролетне су довољне [15.7., 20:32] Srki: Већ 5 комплет завеса This up is the text and I want to remove the content for all from "[" to ":"so ([15.7., 20:32] Srki:) . I tried with import re but it didn't work. Thank you for help

20th Jul 2022, 6:41 PM
Srki
17 odpowiedzi
0
Hi! If I understand you, its super easy. Just put your lines in a list lst, were every element in the list is a string of your lines. Then use slice: for i in range(len(lst)): print(l[i][21:])
20th Jul 2022, 8:00 PM
Per Bratthammar
Per Bratthammar - avatar
+ 2
# Hi! You can try this: s = """[15.7., 20:32] Srki: Смета [15.7., 20:32] Srki: Покрива даску [15.7., 20:32] Srki: Ролетне су довољне [15.7., 20:32] Srki: Већ 5 комплет завеса""" sub = s[:21] print(s.replace(sub, ""))
20th Jul 2022, 8:22 PM
Per Bratthammar
Per Bratthammar - avatar
+ 2
It worked! Tnx man, cheers 🍻
20th Jul 2022, 8:27 PM
Srki
+ 1
What data type is each line? If string: line = "[15.7., 20:32] Srki: Смета" data = line.split(':') print(data) print(data[0]) # output ["[15.7., 20:32] Srki", "Смета"] [15.7., 20:32] Srki
20th Jul 2022, 7:36 PM
Slick
Slick - avatar
+ 1
Thanks man it works too
20th Jul 2022, 8:31 PM
Srki
0
It still doesn't solve problem, I need to print out only text after "[15.7., 20:32] Srki:" so that needs to be removed.
20th Jul 2022, 7:40 PM
Srki
0
I tried everything, but somehow it didn't work
20th Jul 2022, 7:55 PM
Srki
0
This works but it prints out only last line
20th Jul 2022, 7:59 PM
Srki
0
I need to print whole text without that what I mentioned
20th Jul 2022, 7:59 PM
Srki
0
I want to make it out of a string
20th Jul 2022, 8:02 PM
Srki
0
I noticed this problem when I copy multiple messages from WhatsApp and it shows date when it's sent and who sent it so I wanted to make python program who deletes it
20th Jul 2022, 8:03 PM
Srki
0
It's all in one string, I wanted to make solution just to paste one whole text and to get result without that what I mentioned
20th Jul 2022, 8:04 PM
Srki
0
x = "[15.7., 20:32] Srki: Смета" h = x[21:] print(h) This helps only for one line
20th Jul 2022, 8:21 PM
Srki
0
st="""[15.7., 20:32] Srki: Смета [15.7., 20:32] Srki: Покрива даску [15.7., 20:32] Srki: Ролетне су довољне [15.7., 20:32] Srki: Већ 5 комплет завеса""" for s in st.split("\n"): print(s[s.rfind(":")+2:]) #try this
20th Jul 2022, 8:30 PM
Jayakrishna 🇮🇳
- 1
you can use slice and rfind method. may not good as regex.
20th Jul 2022, 7:55 PM
Jayakrishna 🇮🇳
- 1
print(s[s.rfind(":")+1:])
20th Jul 2022, 7:56 PM
Jayakrishna 🇮🇳
- 1
Is that a single line or 4 lines of strings..? For you can use a loop..
20th Jul 2022, 8:03 PM
Jayakrishna 🇮🇳