regexlibreofficelibreoffice-writermnemonics

Removing all but the first letter of every word using regex in LibreOffice Writer


I have found a couple posts around the internet and on here on how to remove all but the first letter of every word in a paragraph (or the whole text) using regex and Microsoft Word, but nothing has seemed to work in LibreOffice Writer.

I have been trying to use the Find and Replace dialog and have regular expressions checked in the options.

As an example:

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

Would become:

L i d s a, c a e, s d e t i u l e d m a.

Keeping punctuation and case sensitivity would be great. I also am not opposed to using a different method/program for this.


Solution

  • Assuming LibreOffice's regex support fixed width lookbehinds, you could match on the following pattern:

    (?<=\w)\w
    

    and then replace with empty string. This pattern will match any word character except those not preceded by word characters (e.g. at the start of a word).

    Here is a running demo.p

    Edit:

    As suggested in the comments, we can optimize the pattern to:

    (?<=\w)\w+
    

    This will match entire sub-words in one go, reducing the number of replacement steps.