Oto mój problem: w zmiennej, która jest tekstem i zawiera przecinki, staram się usuwać tylko przecinki znajdujące się między dwoma ciągami znaków (w rzeczywistości [
i ]
). Na przykład stosując następujący ciąg:Zastąp ciąg znajdujący się między
input = "The sun shines, that's fine [not, for, everyone] and if it rains, it Will Be better."
output = "The sun shines, that's fine [not for everyone] and if it rains, it Will Be better."
wiem jak używać .replace
dla całej zmiennej, ale nie mogę tego zrobić na części. Istnieją pewne tematy zbliża się na tej stronie, ale nie udało mi się wykorzystać je na moje własne pytanie, np:
- Repeatedly extract a line between two delimiters in a text file, Python
- Python finding substring between certain characters using regex and replace()
- replace string between two quotes
oczekiwane wyjście? –