Skip to main content

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)

Metadata

Release files for string-between 0.0.7

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-between 0.0.7
File Size Uploaded Provenance Actions
string_between-0.0.7.tar.gz 6.5 kB Without provenance Details for string_between-0.0.7.tar.gz

Release files / string_between-0.0.7.tar.gz

Download URL string_between-0.0.7.tar.gz
Size 6.5 kB
Tags Source
SHA-256 checksum
How to use checksums
2c805aab7e6582ca6043719a9e3f0c2cdb804fd16c495d38ee151ce0da745861
BLAKE2b-256 checksum
How to use checksums
7848c4d0cf31bd314830b1fbfb4ed20edde8f62796af7662d11a142b1dd7c31b
Upload date
Uploaded using Trusted Publishing?
What is 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

Security for string-between 0.0.7

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