diff --git a/README.md b/README.md index c1229844..1dbf3150 100644 --- a/README.md +++ b/README.md @@ -452,6 +452,108 @@ sed 's/a/x/g' > /dev/null 0,00s user 0,00s system 43% cpu 0,029 total rr x y myfile -o > /dev/null 0,21s user 0,04s system 86% cpu 0,294 total ``` +## Hairy details + +Each part of a run is a stack of layers. Each layer is optional, and works on what the layer before gives it. So the flags work together by their order, not by special rules. + +### On the way in + +#### The pattern + +1. The pattern as typed. `€` is `$` and `§` is `\`. +2. `--literal` (`-L`) makes it plain text, so `.` is a dot. +3. `--void-ignore-case` (`-I`), `--void-multiline` (`-M`), `--dot-all` (`-s`), `--unicode` (`-u`) and `--void-global` (`-G`) decide how the regex works. + +```bash +> echo -n 'a.b' | rexreplace '.' '_' +___ +> echo -n 'a.b' | rexreplace '.' '_' --literal +a_b +``` + +#### The replacement + +1. The replacement as typed, with `€` and `§` as above. Or the piped data with `--replacement-pipe` (`-R`), used as it is. +2. `--js` (`-j`) runs it as code, and the value of the code goes on. `--js-pipe` also gives the code the piped data as `pipe`. +3. `--replacement-file`: what came so far is a path, and the content of that file goes on. +4. `--trim-file` trims it. +5. It goes into the text. `$1` is group 1, `$&` the whole match, and `$$` one `$`, unless the value came from `--js` code, or `--literal-replacement` (`-l`) is given. + +```bash +> echo -n foo | rexreplace '(f)(oo)' '$2$1' +oof +> echo -n foo | rexreplace 'o' '$0.toUpperCase()' --js +fOO +> echo -n PRICE | rexreplace '(PRICE)' 'only $1.99' +only PRICE.99 +> echo -n PRICE | rexreplace '(PRICE)' 'only $1.99' --literal-replacement +only $1.99 +> echo -n 'a {{footer}} b' | rexreplace '\{\{footer\}\}' partials/footer.html --replacement-file --trim-file +a