cap.regex
2.0.0
There is a newer version of this package available.
See the version list below for details.
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
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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
nuke :add-package cap.regex --version 2.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
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
- .NET Regular Expressions for CLI on Linux, macOS and Windows
- .NET Tool Deployment
- NuGet Package
- Permissive MIT License
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 | Versions 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.