Skip to main content

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)

Release files for mgsub 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mgsub 0.1.0
File Size Uploaded
mgsub-0.1.0.tar.gz 3.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mgsub 0.1.0
File Interpreter ABI Platform
mgsub-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size:7.7 kB

Release files / mgsub-0.1.0.tar.gz

Download URL mgsub-0.1.0.tar.gz
Size 3.2 kB
Tags Source
SHA-256 checksum
How to use checksums
092fda9c18826df5b3b075a819f0f8debc7c52813150f4fc876ab67a0745d51a
BLAKE2b-256 checksum
How to use checksums
08b6790a95405dc13cd53ba86bbb4390a91bbf13566ab7819a691f83c195033f
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / mgsub-0.1.0-py3-none-any.whl

Download URL mgsub-0.1.0-py3-none-any.whl
Size 4.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3a384cb77315ce01c8b4fa65dc6a4baff86d7b05cac83e8cd65957cf68427f85
BLAKE2b-256 checksum
How to use checksums
842945381b4b1e6fa52a129223b31314665ac333413ac3e0104ede11efe69d1b
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

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