0%

查找子字符串之间的内容

直接代码。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
s = "123123STRINGabcabc"

def find_between( s, first, last ):
try:
start = s.index( first ) + len( first )
end = s.index( last, start )
return s[start:end]
except ValueError:
return ""

def find_between_r( s, first, last ):
try:
start = s.rindex( first ) + len( first )
end = s.rindex( last, start )
return s[start:end]
except ValueError:
return ""


print find_between( s, "123", "abc" )
print find_between_r( s, "123", "abc" )

[参见](http://stackoverflow.com/questions/3368969/find-string-between-two-substrings)

听首音乐放松一下

author: Jiezhi.G
email: Jiezhi.G@gmail.com

Welcome to my other publishing channels