Skip to main content

string_grab

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

Functions: 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'


Main functions

grab

Returns the first substring between two 'start' and 'end' strings.

Variants: grab_all, grab_until, grab_after.

grab('John likes apples.',
     start='John likes ',
     end='.')

>> 'apples'

inject

Inserts a substring, replacing everything between two 'start' and 'end' strings.

Variants: inject_until, inject_after.

inject('John likes apples.',
       'oranges',
       start='John likes ',
       end='.')

>> 'John likes oranges.'


grab variants

grab_all

Yields all substrings between two 'start' and 'end' strings.

See grab.

results = grab_all('John likes apples. John likes oranges.',
                   start='likes ',
                   end='.')

list(results)
>> ['apples', 'oranges']

grab_until

Returns everything before the 'end' string.

See grab.

grab_until('John likes apples.',
           end=' likes')

>> 'John'

grab_after

Returns everything after the 'start' string.

See grab.

grab_after('John likes apples.',
           start='likes ')

>> 'apples.'


inject variants

inject_until

Inserts a substring, replacing everything before the 'end' string.

See inject.

inject_until('John likes apples.',
             'Sarah',
             end=' likes')

>> 'Sarah likes apples.'

inject_after

Inserts a substring, replacing everything after the 'start' string.

See inject.

inject_after('Sarah likes apples.',
             'oranges.',
             start='likes ')

>> 'Sarah likes oranges.'

Metadata

Release files for string-grab 1.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for string-grab 1.3.0
File Size Uploaded Provenance Actions
string_grab-1.3.0.tar.gz 9.9 kB Without provenance Details for string_grab-1.3.0.tar.gz

Release files / string_grab-1.3.0.tar.gz

Download URL string_grab-1.3.0.tar.gz
Size 9.9 kB
Tags Source
SHA-256 checksum
How to use checksums
67ad57c44ed0fcf15338e10e13f8de519f4169e60d3534fafe8c6d3bb2154fa0
BLAKE2b-256 checksum
How to use checksums
234732c62af90539147a7271eb6f36d53d1e6bf61c7a9dc62ee67fb459a2c2d2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.12

Security for string-grab 1.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page