srgn is a command-line tool for searching and transforming text or source code within precisely defined scopes. Unlike a conventional search-and-replace utility, it can restrict operations to particular syntactic elements, such as comments, strings or other language-specific constructs.
The application combines scopes with actions. A scope determines which parts of the input are eligible for processing, while an action specifies what should happen to that text. Several scopes and actions can be combined to produce more targeted transformations.
srgn uses language grammars to distinguish different parts of source code. For example, a replacement can be restricted to Python docstrings rather than affecting identically named variables or string literals elsewhere in a file.
It can also process files recursively, selecting relevant source files and applying transformations across a project.
This is free and open source software.
Key Features
- Search source code using regular expressions.
- Restrict operations to specific portions of the input.
- Use grammar-aware scopes based on Tree-sitter.
- Support C, C#, Go, HCL, Python, Rust and TypeScript grammar scopes.
- Select predefined language constructs such as comments and strings.
- Define custom Tree-sitter queries for more specialised searches.
- Load custom queries from files.
- Combine language scopes with regular-expression filters.
- Support advanced regular expressions including lookaround assertions.
- Replace matching text using capture groups.
- Apply character case transformations, including title case.
- Delete or squeeze matching text.
- Perform Unicode normalisation and other text transformations.
- Combine multiple actions within a single operation.
- Search source files recursively.
- Identify relevant files using extensions and shebang lines.
- Provide explicit failure conditions for expected or unexpected matches.
- Cross-platform support – runs on Linux, macOS, and Windows.
Website: github.com/alexpovel/srgn
Support:
Developer: Alex Povel
License: MIT License

srgn is written in Rust. Learn Rust with our recommended free books and free tutorials
| Explore Linux | |
|---|---|
| Best Free and Open Source Software - A huge collection of recommended free and open source software covering every major category. | |
| In-depth Linux Software Reviews - Detailed assessments of Linux software covering features, usability and overall quality. | |
| The Big List of Active Linux Distros - An extensive collection of actively developed Linux distributions. | |
| Open Source Alternatives - Alternatives to software and services from Google, Microsoft, Apple, Adobe, IBM, Autodesk, Oracle and others. | |
| Essential Linux System Tools - Indispensable utilities for monitoring, maintaining and managing Linux systems. | |
| Linux Productivity Tools - Useful utilities for improving productivity and streamlining everyday tasks. | |
| Alternatives to Popular CLI Tools - Modern alternatives to familiar command-line utilities supplied with Linux systems. | |
| Awesome Free Linux Game Tools - Tools, utilities and companion software that improve gaming on Linux. | |
| Machine Learning on Linux - Machine learning and deep learning software, self-hosted applications and practical tools. | |
| Saving Money with Linux - Practical ways to reduce electricity consumption and lower computing costs with Linux. | |
| Linux Candy - Fun, entertaining and sometimes delightfully quirky software from the lighter side of Linux. | |

Please read our Comment Policy before commenting.