3 回答

TA貢獻(xiàn)1757條經(jīng)驗(yàn) 獲得超8個(gè)贊
您可以使用正則表達(dá)式:
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組來(lái)執(zhí)行您喜歡的操作。

TA貢獻(xiàn)1776條經(jīng)驗(yàn) 獲得超12個(gè)贊
我將使用.find()字符串切片:
s = 'lksalksapointdlksla'
s = s[s.find('point'):]
print(s)

TA貢獻(xiàn)1810條經(jīng)驗(yàn) 獲得超5個(gè)贊
你能行的:
text = "kljkghglpointsdfasfsd"
text = text.split("point")[1]
print(text)
添加回答
舉報(bào)