Using Dotstar · Part 4

Replacing

Replace, at the end of the row above the pattern, switches from finding to replacing. A replacement field opens under the pattern, and the text with every match replaced shows below the test text, each replacement marked.

Replace on: log lines rewritten as day, month, level and user, each replacement marked in the result.

The replacement’s syntax

The replacement is written in the flavor’s own syntax, as the language would read it, so what works here works in your code:

  • JavaScript: $1, $<name>, $&
  • PCRE2 and Go: $1, ${name}
  • Python: \1, \g<name>
  • .NET and Java: $1, ${name} (in Java a plain dollar is \$)

Suggestions help here too: $ or \ in the replacement lists the pattern’s groups, written the flavor’s way. The Explain tab explains the replacement, part by part. The lesson on replacing has the syntax of more languages.

Escapes

The \n at the end of the replacement field turns on escapes: \n, \t and the like then mean a line break and a tab, as in a string in code. (Python always reads them.)

Taking the result

Copy above the result takes all of it. Use as text, in the Chain tab, makes the result the new text, to go on from there; Chain is also where to put several replacements one after another (see Chain).

In Files, with Replace on, each hit shows what replaces it, and Replace in files… changes the files themselves, keeping a backup of each first.