ppre user guide
The basics of ppre, a regular-expression tool that finds files, searches text, renames files and edits text with one grammar, in place of find, grep, perl rename and sed.
What is ppre
ppre (Powerful Pattern Replacement Engine) is a command-line tool written in Rust by PPOPPO Corp. Finding files, searching text, renaming files and editing text usually take four tools with four different grammars. ppre does all four with one.
| Instead of | Use | To |
|---|---|---|
find | ppre find | Find files by name |
grep | ppre grep | Search file contents |
rename (perl) | ppre rename | Rename files |
sed | ppre edit | Edit file contents |
- One grammar — the four commands share the same word order, the same options and the same pattern language. What you learn for one carries over to the other three.
- Regular expressions only — files are selected by regular expression too:
'\.rs$', not*.rs. There is no second pattern language to switch to. - One regex dialect — every command reads a pattern the same way, including lookaround, backreferences and named groups.
- Nothing is guessed — a spelling ppre does not accept is refused by name. Where a rewrite exists, the error gives it.
Supported platforms are Linux and macOS.
One grammar, four commands
Every command line has the same shape.
ppre <command> [options] <pattern> [path...]
The four commands are the four combinations of two questions: do you mean file names or file contents, and do you want to read or to change?
| Read | Change | |
|---|---|---|
| File names | ppre find | ppre rename |
| File contents | ppre grep | ppre edit |
Only the command word changes. The options, the regular expression and the paths stay where they are.
ppre find -r 'draft' notes # list the names that match
ppre grep -r 'draft' notes # print the lines that match
ppre rename -r 's/draft/review/' notes # rewrite the matching part of each name
ppre edit -r 's/draft/review/g' notes # rewrite the matching text in each file
| Part | Rule |
|---|---|
<command> | find, grep, rename or edit. |
[options] | One spelling has one meaning on every command. Every command accepts every option. A command that cannot act on an option ignores it, and ppre help <command> lists those options with the reason. |
<pattern> | A regular expression. The commands that read (find, grep) take it bare. The commands that change (rename, edit) take the same regular expression inside a substitution, s/regex/replacement/, because a change also needs a replacement. |
[path...] | Files or directories. A file you name is always read. A directory is walked, and -r is what descends into its subdirectories. |
These options are honoured by all four commands, with the same meaning.
| Option | Meaning |
|---|---|
-r, --recursive | Descend into subdirectories. Without it, only the top level of a directory is read. |
--max-depth <N> | Descend at most N levels (1 = direct children). Implies -r. |
-m, --filter <REGEX> | Work only on paths that match the regular expression. Repeatable. |
--exclude <REGEX> | Leave out paths that match the regular expression. Repeatable. |
--include-ignored | Also walk what .gitignore excludes. |
--exclude-hidden | Skip hidden entries (names that start with .). |
--follow-symlinks | Follow symbolic links while walking. |
-i, --ignore-case | Match without regard to case. |
--normalize | Match every Unicode spelling (NFC/NFD) of the text. |
The options that differ follow from the job, not from the tool. -n (--dry-run) previews a change, so it belongs to rename and edit. Options that shape a listing, such as -l, -c and -o, belong to grep. The grammar around them does not change.
Installation
ppre is currently built and installed from source. You need a Rust toolchain and just.
just install
This builds a release binary and installs it to ~/.local/bin/ppre, with its manual page (man ppre). Installation stops if another ppre comes first on your PATH, so make sure ~/.local/bin is near the front of PATH.
If you use ppre every day, you can add short aliases to your shell startup file (~/.zshrc or ~/.bashrc).
# ppre shortcuts
alias ppf='ppre find'
alias ppg='ppre grep'
alias ppr='ppre rename'
alias ppe='ppre edit'
After that, ppg -r 'draft' . means ppre grep -r 'draft' ..
First steps
The blocks below show standard output. rename and edit also print a short summary of the run on standard error.
-
Make three small files to practise on.
mkdir -p demo/notes && cd demo printf 'status: draft\n' > notes/draft-01.md printf 'status: draft\n' > notes/draft-02.md printf 'status: final\n' > notes/final-03.md -
Find the files whose name matches
draft.$ ppre find -r 'draft' . ./notes/draft-01.md ./notes/draft-02.md -
Search for the lines that match the same pattern. Only the command word changed.
$ ppre grep -r 'draft' . ./notes/draft-01.md:1:status: draft ./notes/draft-02.md:1:status: draft -
Preview an edit.
-nchanges nothing, and--diffprints the change as a unified diff.$ ppre edit -r -n --diff 's/draft/review/g' . --- a/notes/draft-01.md +++ b/notes/draft-01.md @@ -1,1 +1,1 @@ -status: draft +status: review --- a/notes/draft-02.md +++ b/notes/draft-02.md @@ -1,1 +1,1 @@ -status: draft +status: review -
Run the same line without
-nand--diffto apply it.ppre edit -r 's/draft/review/g' . -
Preview a rename, then apply it. The output is the plan: the old name, a tab, the new name.
$ ppre rename -r -n 's/draft-(\d+)/review-$1/' . ./notes/draft-01.md ./notes/review-01.md ./notes/draft-02.md ./notes/review-02.md $ ppre rename -r 's/draft-(\d+)/review-$1/' . ./notes/draft-01.md ./notes/review-01.md ./notes/draft-02.md ./notes/review-02.md -
Check the result.
$ ppre find -r '\.md$' . ./notes/final-03.md ./notes/review-01.md ./notes/review-02.md
Regular expressions
One dialect serves every place a pattern goes: the pattern of find and grep, the pattern half of a substitution in rename and edit, and the value of --filter and --exclude.
| Syntax | Meaning |
|---|---|
\d \w \s . | A digit, a word character, white space, any character |
^ $ \b | Start and end of a line (of the name, for find and rename), word boundary |
* + ? {2,4} | Repetition. Add ? for the shortest match: .*? |
(…) (?<name>…) | A group, a named group. Groups need no backslash |
(?=…) (?!…) | Lookahead, negative lookahead |
(?<=…) (?<!…) | Lookbehind, negative lookbehind (fixed width) |
\1 \k<name> | Backreference to a group |
(?>…) | Atomic group |
A glob is not a pattern. ppre find -r '*.md' . is refused, and the error gives the regular expression to use. The same holds for -g, which points at --filter.
| Glob | Regular expression |
|---|---|
*.txt | \.txt$ |
test_* | ^test_ |
*config* | config |
Spellings whose meaning differs between regex engines are refused by name too: possessive quantifiers (a++), recursion ((?R)), \K and variable-width lookbehind. Where a rewrite exists, the error gives it.
For find and grep, -F takes the pattern as literal text and -e adds another pattern (either may match).
Substitutions
rename and edit take the expression that sed and perl rename take.
s/regex/replacement/flags
- Delimiter — another punctuation character such as
#or|can replace/, which helps when the text holds slashes:s#/usr/local#/opt#. - Flags —
greplaces every match. Without it, only the first match in each file (or name) is replaced.iignores case,slets.match a line break,Umakes repetition match the shortest text. - Transliteration —
y/a-z/A-Z/maps characters one for one. Both sets must have the same length.
The replacement is a superset of sed's. Every sed spelling works, and the $ forms work beside it.
| In the replacement | Meaning |
|---|---|
\1 … \9, $1, ${1} | A numbered group |
${name} | A named group |
& | The whole match |
\U \L … \E | Upper case or lower case up to \E |
\u \l | Upper case or lower case for the next character |
\n \t | A line break, a tab |
$$ | A literal $ |
ppre edit 's/(?<y>\d{4})-(?<m>\d{2})-(?<d>\d{2})/${d}.${m}.${y}/g' dates.txt # 2026-11-24 → 24.11.2026
ppre edit 's/_(\w)/\u$1/g' names.txt # hello_world → helloWorld
ppre rename 's/\.(\w+)$/.\L$1\E/' *.TXT # readme.TXT → readme.txt
Coming from find, grep, rename and sed
| Habit | ppre |
|---|---|
find . -name '*.rs' | ppre find -r '\.rs$' . |
find . -type d -name 'src' | ppre find -r -t d '^src$' . |
find . -maxdepth 1 -name '*.md' | ppre find --max-depth 1 '\.md$' . |
grep -rn 'TODO' src | ppre grep -r 'TODO' src |
grep -r --include='*.rs' 'TODO' . | ppre grep -r -m '\.rs$' 'TODO' . |
grep -rl 'TODO' . | ppre grep -rl 'TODO' . |
rename 's/\.txt$/.md/' *.txt | ppre rename 's/\.txt$/.md/' *.txt |
rename -n 's/old/new/' *.txt | ppre rename -n 's/old/new/' *.txt |
sed -i 's/old/new/g' file.txt | ppre edit 's/old/new/g' file.txt |
sed -i -E 's/(a)(b)/\2\1/g' file.txt | ppre edit 's/(a)(b)/\2\1/g' file.txt |
find + xargs sed -i over a tree | ppre edit -r -m '\.rs$' 's/old/new/g' . |
Four things differ from the habit.
-rdescends.findwalks the whole tree by default. ppre reads the top level until-ror--max-depthsays otherwise, and a run that stayed at the top level says so.- Regular expressions, not globs.
'\.rs$'wherefind -nameandgrep --includetake'*.rs'. - Groups without backslashes.
(…)groups and\dis a digit, with no-Eto remember. gcovers the file.sedwithoutgreplaces the first match on every line.ppre editwithoutgreplaces the first match in the file. Writegto replace every match.
A pipe with no path is the input for grep and edit, as it is for grep and sed.
git log --oneline | ppre grep -i 'fix'
git log --oneline | ppre edit 's/^(\w+) /[$1] /g'
Good to know
- What a walk reads — inside a git repository a walk skips what
.gitignoreexcludes. It reads hidden files and never enters.git/. A path you name on the command line is always read, whatever the filters say. - Edits are backed up —
editsaves the original under.ppre_backups/before it writes.ppre restore --listshows the backups, andppre restore --checkpoint <ID>puts a whole run back. SetPPRE_BACKUP=noneto keep no backups. - Renames are planned —
renamechanges only a file's own name, never its directory. Every rename is planned before the first one runs, so two files that would land on one name are refused before anything moves. A rename takes no backup. Its output is the record, and the inverse expression undoes it. - Output pipes cleanly — standard output holds the result and nothing else. Summaries and notes go to standard error.
- Exit codes —
0success,1nothing matched (find,grep),2partly done, for example when a file could not be read. An error such as an invalid pattern or a missing path exits with10or above. - Korean names on macOS — a name stored decomposed (NFD) does not match text typed composed (NFC). ppre says so when it happens, and
--normalizematches both. - More help —
ppre help <command>andman pprehold the full reference.ppre learn basicsis a regular-expression tutorial.