Extraire une ou plusieurs sous-chaînes entre deux chaînes de démarrage et d'extrémité.
Fonctions: Grab, Grab_ALL, Grab_until, Grab_After, Inject, Inject_Util, 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'Renvoie la première sous-chaîne entre deux chaînes «début» et «fin».
Variants: Grab_ALL, Grab_until, Grab_After.
grab ( 'John likes apples.' ,
start = 'John likes ' ,
end = '.' )
>> 'apples' Insère une sous-chaîne, remplaçant tout entre deux chaînes «début» et «fin».
Variants: inject_until, inject_after.
inject ( 'John likes apples.' ,
'oranges' ,
start = 'John likes ' ,
end = '.' )
>> 'John likes oranges.'Donne toutes les sous-chaînes entre deux chaînes «début» et «fin».
Voir Grab.
results = grab_all ( 'John likes apples. John likes oranges.' ,
start = 'likes ' ,
end = '.' )
list ( results )
>> [ 'apples' , 'oranges' ]Renvoie tout avant la chaîne «fin».
Voir Grab.
grab_until ( 'John likes apples.' ,
end = ' likes' )
>> 'John' Renvoie tout après la chaîne «Démarrer».
Voir Grab.
grab_after ( 'John likes apples.' ,
start = 'likes ' )
>> 'apples.'Insère une sous-chaîne, remplaçant tout avant la chaîne «fin».
Voir Inject.
inject_until ( 'John likes apples.' ,
'Sarah' ,
end = ' likes' )
>> 'Sarah likes apples.' Insère une sous-chaîne, remplaçant tout après la chaîne «Démarrer».
Voir Inject.
inject_after ( 'Sarah likes apples.' ,
'oranges.' ,
start = 'likes ' )
>> 'Sarah likes oranges.'