Use fastmod to perform large-scale codebase refactors using regular expressions. The tool is optimized for an interactive workflow where you review changes match-by-match.
Interactive Mode
Use the -m flag to enter interactive mode. For every match found, fastmod will show a colored diff and prompt you to:
- Accept the change.
- Reject the change.
- Edit the line using your configured
$EDITOR.
Regex Syntax and Capture Groups
fastmod uses the Rust regex crate. Note these specific syntax requirements:
- Capture Groups: Use
${1}, ${2}, etc., in the replacement string instead of Python-style \1 or \2. - Literal Dollar Signs: Use
$$ to represent a literal $ in the replacement string. - Shell Escaping: It is highly recommended to wrap your replacement string in single quotes (
'...') to prevent your shell (like bash) from interpreting the $ characters before they reach fastmod.
Specifying Targets
You can specify files or directories to process as positional arguments after the regex and substitution strings. You can also limit processing to specific file extensions using the --extensions flag.
# Example: Replacing <font color="..."> with <span style="color: ..."> across a directory
fastmod -m --extensions php,html \
'<font *color="?(.*?)"?>(.*?)</font>' \
'<span style="color: ${1};">${2}</span>' \
/home/jrosenstein/www