string_grab
1.0.0
在兩個啟動和末端字符串之間提取一個或多個子字符串。
函數:grab,grab_all,grab_until,grab_after,inject,inject_until,inject_after。
from string_grab import grab
text = '''Gender: female
Race: White
Birthday: 3/23/1973
Mobile: 715-523-1076
Mobile: 715-563-3967
Street: 4674 Lynn Avenue
City, State, Zip: Eau Claire, Wisconsin(WI), 54701'''
birthday = grab ( text , start = 'Birthday: ' , end = ' n ' )
print ( birthday )
>> '3/23/1973'返回兩個“啟動”和“端”字符串之間的第一個子字符串。
變體:grab_all,grab_until,grab_after。
grab ( 'John likes apples.' ,
start = 'John likes ' ,
end = '.' )
>> 'apples' 插入一個子字符串,替換兩個“啟動”和“結束”字符串之間的所有內容。
變體:inject_until,inject_after。
inject ( 'John likes apples.' ,
'oranges' ,
start = 'John likes ' ,
end = '.' )
>> 'John likes oranges.'在兩個“啟動”和“端”字符串之間產生所有子字符串。
見抓。
results = grab_all ( 'John likes apples. John likes oranges.' ,
start = 'likes ' ,
end = '.' )
list ( results )
>> [ 'apples' , 'oranges' ]在“結束”字符串之前返回所有內容。
見抓。
grab_until ( 'John likes apples.' ,
end = ' likes' )
>> 'John' 在“開始”字符串之後返回所有內容。
見抓。
grab_after ( 'John likes apples.' ,
start = 'likes ' )
>> 'apples.'插入一個子字符串,在“端”字符串之前替換所有內容。
請參閱注入。
inject_until ( 'John likes apples.' ,
'Sarah' ,
end = ' likes' )
>> 'Sarah likes apples.' 插入一個子字符串,替換“開始”字符串之後的所有內容。
請參閱注入。
inject_after ( 'Sarah likes apples.' ,
'oranges.' ,
start = 'likes ' )
>> 'Sarah likes oranges.'