Skip to main content

A CLI utility for replacing multi-line strings in files. Supports textual replacements with wildcard matching indentation-aware replacements.

Project description

Multi-Line Replacer (mlr)

Copyright 2025 Caleb Evans
Released under the MIT license

tests Coverage Status

Multi-Line Replacer is a CLI utility for replacing multi-line hunks of strings across one or more files. Matching is mostly textual, but wildcard matching is supported, and replacements are indentation-aware.

Usage

The workflow takes one or more files on which to run replacements, and then a series of "replacement rule" files with the -r flag:

mlr .github/workflows/*.yml -r example-rules/uv-gha.md

Each replacement rule must be a Markdown file with one or more pairs of GFM fenced code blocks (see documentation). Every odd code block represents the target text to replace, and every even code block represents the textual replacement. All other Markdown formatting is ignored, so feel free to add headings, explainer text, or anything else!

This rule replaces flake8 with ruff in a Github Actions linting workflow.

## flake8

```yml
- name: Run flake8
  run: flake8 MATCH_UNTIL_END_OF_LINE
```

## ruff

```yml
- name: Run ruff
  run: |
    uv run ruff check .
    uv run ruff format --check .
```

The language specifier at the start of each code fence is ignored by the utility. Still, it is highly recommended to specify so that syntax highlighting is enabled in your editor (for a better authoring experience).

Wildcard Matching

There are two special wildcard variables:

  • MATCH_UNTIL_END_OF_LINE ([^\n]*)
  • MATCH_ALL_BETWEEN ([^\n]*?)

These variables can be used anywhere in a rule (no word boundaries required).

More Examples

To better understand the expected rules format and what's allowed, please see the example-rules directory.

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

multi_line_replacer-1.0.0b1.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

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

multi_line_replacer-1.0.0b1-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file multi_line_replacer-1.0.0b1.tar.gz.

File metadata

File hashes

Hashes for multi_line_replacer-1.0.0b1.tar.gz
Algorithm Hash digest
SHA256 fd2a12eb91ee4e6c073121e2137973cce56dbb333754de63f52e887824a69cf7
MD5 04b884b97c17356469a52ccef3ef711d
BLAKE2b-256 f81f6cbf3d7f79fb4e7ca60c7a9ca4caf57f9e9ae97163b6e5768e793b142e9f

See more details on using hashes here.

File details

Details for the file multi_line_replacer-1.0.0b1-py3-none-any.whl.

File metadata

File hashes

Hashes for multi_line_replacer-1.0.0b1-py3-none-any.whl
Algorithm Hash digest
SHA256 339dfc24facfc7bdbc847b3b8761b263f8acc4d3a77cc0d6783f201dcd41b1c1
MD5 3487b5395f3c296fb50bec78f3c49340
BLAKE2b-256 0bca5aa2eb332b32c89c7d432c92adc56704d421ac866c210be31c0209be63a0

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