Pattern replacements - MX-Futhark/hook-any-text GitHub Wiki
Character, sequence and pattern substitutions enable the user to replace and remove strings. They are particularly useful to get rid of unecessary formatting hints that get caught in the final outputs.
This feature is available at Tools > Options > Replacements
Basic features
By clicking the "add" button, a new empty replacement will be created. The "sequence" column determines what needs to be replaced and the "replacement" columns what the replacement is. By leaving the later empty, it simply removes the content of the former from an input every time the sequence is encountered.
For example, "a" as the sequence and "" as a replacement will remove all "a"s from a string: "abracadabra" -> "brcdbr".
Replacements can be reordered using the arrows on the right-side of the table. If one replacement interferes with another one, they will be applied from top to bottom.
Escaping characters
Character escaping is activated when the checkbox in the "escape" column is checked. For those not familiar with the concept of character escaping, the idea is to represent a non-printable character by an antislash and another character. It can also be used to represent a unicode character by its codepoint. Here are the most important correspondencies:
| character | escaped version |
|---|---|
| tab | \t |
| line break | \n |
| antislash | \\ |
| unicode character | \uXXXX where XXXX is the codepoint of the character in hexadecimal |
Regular expressions
Regular expressions are activated when the checkbox in the "regex" column is checked. More information here. Please note that HAT uses Java regular expressions.
Types of replacements
There are three types of replacements: STR2STR (which stands for string to string), HEX2HEX (hexadecimal to hexadecimal) and HEX2STR (hexadecimal to string). STR2STR is selected by default.
HEX2HEX makes it possible to replace hexadecimal patterns by another hexadecimal sequence. It's useful when formatting information have no legible equivalent.
HEX2STR makes it possible to force HAT to interpret a given hexadecimal sequence as a specific string. It can be used to replace hard-coded hexadecimal sequences that represent a string specific to a game but not in the encoding used by the game. For example, in Fate/Extra, 8745 represents the "!?" single character (Unicode: \u2049) which does not exist in Shift-JIS. This case is treated as follows:
| sequence | replacement | escape | regex | type |
|---|---|---|---|---|
| 8745 | \u2049 | X | HEX2STR |