string_grab
1.0.0
2つの開始文字列とエンド文字列の間に1つまたは複数のサブストリングを抽出します。
関数: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'2つの「開始」と「終了」文字列の間の最初のサブストリングを返します。
バリアント:grab_all、grab_until、grab_after。
grab ( 'John likes apples.' ,
start = 'John likes ' ,
end = '.' )
>> 'apples' サブストリングを挿入し、すべてを2つの「開始」と「終了」文字列の間に置き換えます。
バリアント:Inject_until、Inject_after。
inject ( 'John likes apples.' ,
'oranges' ,
start = 'John likes ' ,
end = '.' )
>> 'John likes oranges.'2つの「開始」と「終了」文字列の間にすべてのサブストリングを生成します。
グラブを参照してください。
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.' サブストリングを挿入し、「start」文字列の後にすべてを交換します。
注入を参照してください。
inject_after ( 'Sarah likes apples.' ,
'oranges.' ,
start = 'likes ' )
>> 'Sarah likes oranges.'