python删除文本文件中特定结束行的特定起始行

时间:2017-02-10 06:31:16

标签: python-3.x anaconda

我有以下数据:

test="1. My Contact Number (Nortel/Mobile): 7774096182 2. My Preferred Time (in IST) to be contacted: 11am to 8pm Please book a daily bridge line, below are the details: Start Date: 06-July-2016 End Date: 05-Aug-2016 Time: 3 pm to 6 pm ( 3-hr duration) Number of participants: 25 on every friday We require the bridge line daily during this slot. Regards, Smriti Varma."

test1="Hi Team, Please arrange Audio Bridge call thru Nortel & Landline only for tomorrow Dated 16-Jun-2016 between 12.30 PM to 1.30 PM (IST), Number of Paticipants: 06 1. My Contact Number (Nortel/Mobile): 2. My Preferred Time (in IST) to be contacted:"

我不希望两者都有这条线:

text="1. My Contact Number (Nortel/Mobile): 2. My Preferred Time (in IST) to be contacted:","1. My Contact Number (Nortel/Mobile): 7774096182 2. My Preferred Time (in IST) to be contacted: 11am to 8pm"

1 个答案:

答案 0 :(得分:0)

我不知道您想要的最终结果,但您可以使用str.replace()
如下所示:

test = "1. My Contact Number (Nortel/Mobile): 7774096182 2. My Preferred Time (in IST) to be contacted: 11am to 8pm Please book a daily bridge line, below are the details: Start Date: 06-July-2016 End Date: 05-Aug-2016 Time: 3 pm to 6 pm ( 3-hr duration) Number of participants: 25 on every friday We require the bridge line daily during this slot. Regards, Smriti Varma."

test1 = "Hi Team, Please arrange Audio Bridge call thru Nortel & Landline only for tomorrow Dated 16-Jun-2016 between 12.30 PM to 1.30 PM (IST), Number of Paticipants: 06 1. My Contact Number (Nortel/Mobile): 2. My Preferred Time (in IST) to be contacted:"

text = ["1. My Contact Number (Nortel/Mobile): 2. My Preferred Time (in IST) to be contacted:","1. My Contact Number (Nortel/Mobile): 7774096182 2. My Preferred Time (in IST) to be contacted: 11am to 8pm"]

test_modified = test.replace(text[0], "")
test1_modified = test1.replace(text[1], "")

How to use string.replace() in python 3.x

但这取决于你的测试的复杂性"字符串,如果你想一般寻找它们。