Skip to main content

Extract one or multiple substrings between two start and end strings.

Project description

string_grab

Extract one or multiple substrings between two start and end strings.

text = """Gender: female
       Race: White
       Birthday: 3/23/1973 (50 years old)
       Mobile: 715-523-1076
       Mobile: 715-563-3967
       Street: 4674 Lynn Avenue
       City, State, Zip: Eau Claire, Wisconsin(WI), 54701"""
from string_grab import grab

birthday = grab(text, start="Birthday: ", end=" (")
print(birthday)

>> "3/23/1973"
from string_grab import grab_until

gender_prompt = grab_until(text, end=" female")
print(gender_prompt)

>> "Gender:"
from string_grab import grab_after

zip_code = grab_after(text, start="Wisconsin(WI), ")
print(zip_code)

>> "54701"
from string_grab import grab_all

for number in grab_all(text, start="Mobile: ", end="\n"):
    print(number)

>> "715-523-1076"
>> "715-563-3967"
from string_grab import inject

inject(text, "611 Waterwheel Ln", start="Street: ", end="\n")

>> """Gender: female
   Race: White
   Birthday: 3/23/1973 (50 years old)
   Mobile: 715-523-1076
   Mobile: 715-563-3967
   Street: 611 Waterwheel Ln
   City, State, Zip: Eau Claire, Wisconsin(WI), 54701"""

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

string_grab-1.2.1.tar.gz (9.6 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page