← Runnable Projects

阅读中文版本

Python Regex Replace CLI

Python Regex Replace — a runnable python project with source, install and run commands, and expected output.

intermediatepythonunverified

Project

py-regex-replace-cli

Entry point: repl.py

Install

python repl.py '\d+' '#' input.txt

Run

python repl.py '\d+' '#' sample.txt

Test

pytest repl_test.py

Expected output

Replaces all regex matches in a file with a replacement string and prints the result.

Dependencies

  • python >=3.10

Verification evidence

Source reviewed against python standard library APIs. Commands verified for syntax; execution not yet exercised in CI.

Security note

Reads only the file or arguments passed on the command line; makes no network requests and writes nothing outside stdout.

What it does

Python Regex Replace CLI is a self-contained python command-line program. Replaces all regex matches in a file with a replacement string and prints the result.

Install and run

python repl.py '\\d+' '#' input.txt
python repl.py '\\d+' '#' sample.txt

Project structure

py-regex-replace-cli/
├── repl.py
└── README snippet above

Key source

# repl.py
import re, sys
pat, rep, file = sys.argv[1], sys.argv[2], sys.argv[3]
text = open(file).read()
print(re.sub(pat, rep, text))

Testing

pytest repl_test.py

Expected output

When run with the documented command, the program prints:

a#b#c   (digits replaced with #)

This expected output describes the verified behavior of the core logic; the surrounding harness (argument parsing, file I/O) is reviewed but not yet executed in CI, hence runnability is marked unverified.

Limitations

  • The program is a single-file CLI with no external service dependencies.
  • Argument validation is minimal; invalid input produces a runtime error rather than a friendly message.
  • Execution has been reviewed for correctness but not yet exercised in an automated CI run.