cap.regex 2.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet tool install --global cap.regex --version 2.0.0
                    
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest
                    
if you are setting up this repo
dotnet tool install --local cap.regex --version 2.0.0
                    
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=cap.regex&version=2.0.0
                    
nuke :add-package cap.regex --version 2.0.0
                    

.NET

regex

Search and replace with .NET regular expressions from the command line, using the same engine as your C# code.

Why not grep or ripgrep?

Use them for general text search, they are faster and more widely installed. Use regex when you need the .NET flavor:

  • Try a pattern on the CLI, then paste it into C# unchanged. No dialect differences.
  • .NET-only features such as balancing groups, and named groups in replacements (--replace "id=${name}").
  • Lookarounds and backreferences without extra flags or a separate engine.
  • One tool with the same behavior on Linux, macOS and Windows, installed via dotnet tool.

Features

Install

Requires the .NET 10 SDK or runtime.

dotnet tool install --global cap.regex

Update to the latest version:

dotnet tool update --global cap.regex

Options

Usage:

  regex [<pattern> [<path>...]] [options]

Arguments:
  <pattern>  The search pattern as .NET Regular Expression (RegEx).
  <path>     File or directory to operate. (A directory must end with a directory separator)

Options:
  -R, --replace <replace>        replacement Pattern (regex)
  -c, --case-sensitive           enables case-sensitive behavior - btw. disables the by default enabled ignore-case option
  -f, --filter <filter>          wildcard based file filter, e.g. *.txt [default: *.*]
  -r, --recursive                progress all subdirectories
  --offset-width <offset-width>  output-formatting: set the count of characters used for the offset column [default: 6]
  -o, --only-matching            prints only the match
  -m, --max-count <max-count>    limit matches to the given count
  -v, --verbose                  show additional information
  -V, --version                  show version information
  -?, -h, --help                 Show help and usage information

Exit code is 0 on success and 1 on errors (e.g. missing pattern, invalid regular expression or invalid option value).

Usage Examples

Find "Hello" in all *.txt files in this folder and all subfolders

C:>regex --recursive --filter *.txt Hello ./

Search case-sensitive

regex --case-sensitive Hello notes.txt

Replace with a named group (rewrites the file, files without matches stay untouched)

regex "Name:(?<name>[A-Za-z]+)" --replace "id=${name}" names.txt

Changelog

See CHANGELOG.md.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

Version Downloads Last Updated
2.1.0 132 10/3/2026
2.0.1 107 9/25/2026
2.0.0 104 9/25/2026
1.2.0 898 11/5/2021
1.1.0 519 11/5/2021
1.0.0 539 10/28/2021