Skip to main content

TBA

Project description

string_between

Using string_between

from string_between import string_between

# syntax
string_between(left, right, subject, [,start [,end]] [,greedy=False] [,inclusive=False] [,repl=None] [,retn_all_on_fail=False] [,retn_class=False] [,rightmost=False]) -> str

Return the substring delineated by `left` and `right` within the search
space subject[start:end].  Optional default_arguments `start` and `end`
are interpreted as per slice notation.

Return the string between `left` and `right` or empty string on failure

@param left str|re|list: left anchor, or '' for start of subject; regex must be compiled
@param right str|re|list: right anchor, or '' for end of subject; regex must be compiled
@param subject: string to be searched
@param start: start index for search
@param end: start and end are interpreted as in slice notation.
@param greedy: match biggest substring possible
@param inclusive: include anchors in result
@param repl [str|callable]: replace matched substring with repl in result
@param retn_all_on_fail: return original string if match not made
@param retn_class: return result as StringBetweenResult object
@param rightmost: match rightmost substring, possible by greedily searching for `left`; implies `greedy`
@return matched substring | original string | empty | StringBetweenResult object

Note: regular expressions must be compiled

If left and right are lists, then string_between() takes a value from
each list and uses them as left and right on subject. If right has
fewer values than left, then an empty string is used for the rest of
replacement values. The converse applies. If left is a list and right
is a string, then this replacement string is used for every value of left.
The converse also applies.

Examples:
---------

>>> s = 'The *quick* brown [fox] jumps _over_ the **lazy** [dog]'
>>> string_between('[', ']', s)
'fox'

>>> string_between('[', ']', s, inclusive=True)
'[fox]'

>>> string_between('[', ']', s, rightmost=True)
'dog'

>>> string_between('[', ']', s, inclusive=True, greedy=True)
'[fox] jumps _over_ the **lazy** [dog]'

> b'result'

Changelog

0.0.1: initial release (2021-09-07)

0.0.6: many things since then (2020-09-16)

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_between-0.0.7.tar.gz (6.5 kB view details)

Uploaded Source

File details

Details for the file string_between-0.0.7.tar.gz.

File metadata

  • Download URL: string_between-0.0.7.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.7.9

File hashes

Hashes for string_between-0.0.7.tar.gz
Algorithm Hash digest
SHA256 2c805aab7e6582ca6043719a9e3f0c2cdb804fd16c495d38ee151ce0da745861
MD5 144f55e11e75ec9dbabb5b30600b001d
BLAKE2b-256 7848c4d0cf31bd314830b1fbfb4ed20edde8f62796af7662d11a142b1dd7c31b

See more details on using hashes here.

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