亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

從特定點刪除文本

從特定點刪除文本

阿波羅的戰車 2024-01-16 15:39:49
我想刪除可能與 python 中的特定點不同的文本部分前任:lksalksapointdlksla刪除“point”pointdlksla之前的所有內容kljkghglpointsdfasfsd刪除“point”pointsdfasfsd之前的所有內容這可能嗎?
查看完整描述

3 回答

?
陪伴而非守候

TA貢獻1757條經驗 獲得超8個贊

您可以使用正則表達式:


import re


regex = r"(?P<before>.*)(point)(?P<after>.*)"


test_str = "lksalksapointdlksla"


matches = re.finditer(regex, test_str, re.MULTILINE)


for matchNum, match in enumerate(matches, start=1):

    

    print ("Match {matchNum} was found at {start}-{end}: {match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group()))

    

    for groupNum in range(0, len(match.groups())):

        groupNum = groupNum + 1

        

        print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = match.start(groupNum), end = match.end(groupNum), group = match.group(groupNum)))

然后,您可以使用before和after組來執行您喜歡的操作。


查看完整回答
反對 回復 2024-01-16
?
叮當貓咪

TA貢獻1776條經驗 獲得超12個贊

我將使用.find()字符串切片:


s = 'lksalksapointdlksla'

s = s[s.find('point'):]

print(s)


查看完整回答
反對 回復 2024-01-16
?
森欄

TA貢獻1810條經驗 獲得超5個贊

你能行的:


text = "kljkghglpointsdfasfsd"

text = text.split("point")[1]

print(text)


查看完整回答
反對 回復 2024-01-16
  • 3 回答
  • 0 關注
  • 172 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號