Skip to main content

Simple tools for downloading, cleaning, extracting and parsing content

Project description

Simple helper functions for using strings and regular expressions (mostly) interchangeably.

Requirements

  • Python 2.7+

  • Python 3.4+

Module Contents

strutil.is_string(obj)

Check if obj is a string

strutil.is_regex(obj)

Check if obj is a regular expression

strutil.replace(text, old, new, count=None, strip=False)

Replace an old subset of text with new.

old type may be either a string or regular expression.

If strip, remove all leading/trailing whitespace.

If count, replace the specified number of occurence, otherwise replace all.

strutil.remove(text, what, count=None, strip=False)

Like replace, where new replacement is an empty string.

strutil.replace_each(text, items, count=None, strip=False)

Like replace, where each occurrence in items is a 2-tuple of (old, new) pair.

strutil.remove_each(text, items, count=None, strip=False)

Like remove, where each occurrence in items is what to remove.

strutil.contains(text, what)

Check if what occurs in text

strutil.find_first(data, what)

Search for what in the iterable data and return the index of the first match. Return None if no match found.

strutil.splitter(text, token=None, expected=2, default='', strip=False)

Split text by token into at least expected number of results.

When token is None, the default for Python str.split is used, which will split on all whitespace.

token may also be a regex.

If actual number of results is less than expected, pad with default.

If strip, than do just that to each result.

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

strutil-0.1.3.tar.gz (3.4 kB view details)

Uploaded Source

File details

Details for the file strutil-0.1.3.tar.gz.

File metadata

  • Download URL: strutil-0.1.3.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for strutil-0.1.3.tar.gz
Algorithm Hash digest
SHA256 39066dc52f042af3d5423dbc13566400881656fecd649b317f1d5d6bbe03dad1
MD5 d63ac220cd16b168f8337a1efc64e70e
BLAKE2b-256 f3b28a1987c5afa98ae21353dea7e735fd5c8502458cb80acdb6c9b0ebf2f016

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