Methods for Working with the Register

Space dedupe

Very often, after parsing, the register can held a value that contains multiple successive space characters between words, non-breaking spaces, etc. In most cases, you want to normalize such content, or other words, convert all the whitespace characters to regular ASCII spaces and replace all consecutive spaces for one space. To do it, you can use the space_dedupe command. The command does not need arguments, it works with the register modifying its contents.

Below are examples of using space_dedupe in the code:

          - find:
    path: a.somepath
    do:
    # PARSE TEXT CONTENT OF CURRENT BLOCK
    - parse

    # REGISTER HAS NOW: " The\tlink \nis      absent        "
    # USING FUNCTION TO DEDUPLICATE AND NORMALIZE WHITESPACE CHARACTERS
    - space_dedupe
    # REGISTER HAS NOW: " The link is absent "
          

As you can see, the register now has a value with leading and trailing spaces. The next command is used to delete them.