Skip to main content

A tool for easily manipulating strings with patterns using the "Sandwich Method"

Project description

English description follows Japanese.


概要

  • 正規表現よりも簡単な書き方で文字列のパターン的操作ができるツール

特徴

  • 所定文字列で挟むことによって操作箇所を示す、正規表現よりも敢えて自由度が限定された「Sandwitch Method」に基づく
  • この限定により、パターンマッチで頻出の「"」などの記号のエスケープが不要になる
  • 文字列操作で頻出の最短一致がデフォルトになっている

使い方

import sndwch

# 所定の文字列で挟まれた部分を全て取得 [sndwch]
results = sndwch.get("a = {col='orange', col='green'}", "col='", "'")
print(results)	# -> ["orange", "green"]

# 所定の文字列で挟まれた部分を全て置き換え [sndwch]
result = sndwch.rep(
	"a = {col='orange', col='green'}",	# 操作対象の文字列
	"col='", "'",	# 操作箇所を示すパターン (前方, 後方)
	lambda s: s.upper(),	# 操作関数
	outer = False,	# False: preとpostを含まない, True: 含む
)
print(result)	# -> "a = {col='ORANGE', col='GREEN'}"

Overview

  • A tool that allows pattern-based string manipulation with a simpler syntax than regular expressions.

Features

  • Based on the deliberately restricted "Sandwich Method," where target segments are indicated by enclosing them with specified strings, offering less flexibility than regular expressions on purpose.
  • This restriction eliminates the need to escape frequently occurring symbols (like ") in pattern matching.
  • Shortest match (non-greedy matching) is the default behavior, which is common in string manipulation tasks.

Usage

import sndwch

# Retrieve all substrings enclosed by specified strings [sndwch]
results = sndwch.get("a = {col='orange', col='green'}", "col='", "'")
print(results)	# -> ["orange", "green"]

# Replace all substrings enclosed by specified strings [sndwch]
result = sndwch.rep(
	"a = {col='orange', col='green'}",	# Target string
	"col='", "'",	# Pattern indicating the target area (prefix, suffix)
	lambda s: s.upper(),	# Function to apply
	outer = False,	# False: exclude prefix and suffix, True: include them
)
print(result)	# -> "a = {col='ORANGE', col='GREEN'}"

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

sndwch-0.1.0.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sndwch-0.1.0-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sndwch-0.1.0.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.3

File hashes

Hashes for sndwch-0.1.0.tar.gz
Algorithm Hash digest
SHA256 206d06f52b8ebe89e8f093a08d636ba497ab5e1a1c0a4a5c32d080bdaae766d8
MD5 f7d0686cdb3062e69ab1bb225c00ea80
BLAKE2b-256 940ed0cf95d46449dbd4dac2ba8bebf1ad0d7b9fe7b5076a27adafff3b4cd826

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sndwch-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.3

File hashes

Hashes for sndwch-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ecfd9b83ff629eedfb7e610d0422b1b16718d6addae3aadc8dded668c8dfe29b
MD5 88c3aa817db8a768bd517bdf98d35d0a
BLAKE2b-256 43b3a62a8adb215ad525f71b3da1aa015a00efdcf3065266f8e6c3b941f37077

See more details on using hashes here.

Supported by

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