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: 返値のみpreとpostを含む
)
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: pre and post are excluded in args & return value, True: included only in return value
)
print(result) # -> "a = {col='ORANGE', col='GREEN'}"
Metadata
Release files for sndwch 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| sndwch-0.2.0.tar.gz | 3.1 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sndwch-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 6.8 kB
Release files / sndwch-0.2.0.tar.gz
| Download URL | sndwch-0.2.0.tar.gz |
|---|---|
| Size | 3.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ffce642ae304f0729dcd0aef8341a63dc8ee269aec5d4aae957b291f024927f3
|
|
BLAKE2b-256 checksum How to use checksums |
b7829f7865747a3b7f2d85237a03fc4d3398cfe909c3de15d4b65adc4381ac77
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.3
|
Release files / sndwch-0.2.0-py3-none-any.whl
| Download URL | sndwch-0.2.0-py3-none-any.whl |
|---|---|
| Size | 3.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
25008876734c05eccbd13b0ca3d232a4e2a8855ef11ccde35a7ce964b1c1ec42
|
|
BLAKE2b-256 checksum How to use checksums |
46decb7650bed06f827eb0776c8c9286d31ba41c3aeaa56feddad13b02a3af91
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.3
|
Security for sndwch 0.2.0
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.