之間的字符串下面是我的問題:在文本變量中包含逗號,我嘗試刪除位於兩個字符串之間的逗號(實際上是[
和]
)。例如使用下面的字符串:替換位於
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."
我知道如何使用.replace
整個變量,但我不能爲它的一部分做。 有一些主題接近這個網站,但我沒能利用他們爲我自己的問題,如:
- 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
預期的輸出? –