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.'

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.3.0.tar.gz (9.9 kB view details)

Uploaded Source

File details

Details for the file string_grab-1.3.0.tar.gz.

File metadata

  • Download URL: string_grab-1.3.0.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for string_grab-1.3.0.tar.gz
Algorithm Hash digest
SHA256 67ad57c44ed0fcf15338e10e13f8de519f4169e60d3534fafe8c6d3bb2154fa0
MD5 476f0b7b6556fc26b839c0e21ce58e86
BLAKE2b-256 234732c62af90539147a7271eb6f36d53d1e6bf61c7a9dc62ee67fb459a2c2d2

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.3.0 This release

1 file

1.2.1

1 file

1.1.1

1 file

1.1.0

1 file

1.0.0

1 file

0.0.6

1 file

0.0.5

1 file

0.0.4

1 file

0.0.3

1 file

0.0.2

1 file

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page