Skip to content

Transformations

Eutro edited this page May 16, 2022 · 5 revisions

Here is a list of transformations available in the config file.

Literal Replace

The most basic form of replacement.

Pattern: (["'])(?<target>.+)\1->(["'])(?<replacement>.*)\3

Examples: 'l'->'w', "Iron"->"Gold"

Replaces each substring of the translation that matches the literal target sequence with the specified literal replacement sequence.

The replacement proceeds from the beginning of the string to the end, for example, replacing "aa" with "b" in the string "aaa" will result in "ba" rather than "ab".

Regex Replace

Advanced replacement.

Pattern: s(.)(?<pattern>.*?[^\\])\1(?<replace>.*)\1(?<flags>\w*)

Examples: s/(\w|^)s+(\W|$)/$1th$2/g, s/([nm])([ao])/$1y$2/ig

Uses sed inspired syntax.

Replaces the first, or every (with the g flag), substring of the translation that matches the pattern with the given replacement string.

The replacement string may contain references to capture groups.

Note that backslashes (\) and dollar signs ($) in the replacement string may cause the results to be different than if it were being treated as a literal replacement string. Dollar signs may be treated as references to captured subsequences as described above, and backslashes are used to escape literal characters in the replacement string.

Given the regular expression a*b, the input "aabfooaabfooabfoob", and the replacement string "-", with the g flag, this transformation would yield the string "-foo-foo-foo-". Without the g flag, it would yield "-fooaabfooabfoob".

Chanced

God does play dice!

Pattern: (?<chance>\d+(\.\d+)?)% of the time, (?<pat>.+)

Example: 30% of the time, s/(^|\s)(\w)/$1$2-$2/g

The same as pat, but only chance% of the time. For global replacements, this chance is applied to each substitution individually, rather than for the transformation as a whole.