Skip to main content

A safe, multiple, simultaneous string substitution function

Project description

mgsub

A safe, multiple, simultaneous string substitution function

Why do I want this?

You have a string you want to make substitutions on. You want to make many different substitutions at the same time and you want them done in a safe way. For example, you want to shift each word in "hey, how are you?" to the left by replacing "hey" with "how", "how" with "are, etc. This is a lightweight, pure python function with no dependencies to avoid package bloat when being used.

Install it!

You need to have git installed

  1. Clone the repo to your loacl machine. Type this in a command promp/terminal
git clone https://github.com/bmewing/mgsub-python
  1. goto repo directory
cd mgsub-python
  1. install the module
python setup.py install
  1. You are all done!

Usage

Simply pass in a vector of strings to be modified, a vector of patterns to match and a vector of replacements. Then watch as they are safely, simultaneously replaced!

from mgsub import mgsub
mgsub(string, pattern=[], replacement=[], flags=0)

The pattern to match is supplied first and the replacement vector follows.

mgsub("hey, how are you?",["hey","how","are","you"],["how","are","you","hey"])

Matches and replacements can still be supplied as regex exressions. Flags from re can be set to modify how the regex works.

import re
mgsub("Dopazamine is not the same as Dopachloride and is still fake.", 
      [r'[Dd]opa(.*?mine)',"fake"], ["Meta\\1","real"], flags=re.I)

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

mgsub-0.1.0.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

mgsub-0.1.0-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file mgsub-0.1.0.tar.gz.

File metadata

  • Download URL: mgsub-0.1.0.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.27.0 CPython/3.5.2

File hashes

Hashes for mgsub-0.1.0.tar.gz
Algorithm Hash digest
SHA256 092fda9c18826df5b3b075a819f0f8debc7c52813150f4fc876ab67a0745d51a
MD5 296cb839e84c78d1da20807526f845d4
BLAKE2b-256 08b6790a95405dc13cd53ba86bbb4390a91bbf13566ab7819a691f83c195033f

See more details on using hashes here.

File details

Details for the file mgsub-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mgsub-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.27.0 CPython/3.5.2

File hashes

Hashes for mgsub-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3a384cb77315ce01c8b4fa65dc6a4baff86d7b05cac83e8cd65957cf68427f85
MD5 79e98abf49b3aae5ba6dc2403f8bba3a
BLAKE2b-256 842945381b4b1e6fa52a129223b31314665ac333413ac3e0104ede11efe69d1b

See more details on using hashes here.

Supported by

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