Eliminate newlines in google app script using regex

后端 未结 3 1683
后悔当初
后悔当初 2020-12-02 00:32

I\'m trying to write part of an add-on for Google Docs that eliminates newlines within selected text using replaceText. The obvious text.replaceText(\"\\n

3条回答
  •  盖世英雄少女心
    2020-12-02 00:53

    It seems that in replaceText, to remove soft returns entered with Shift-ENTER, you can use \v:

    .replaceText("\\v+", "")
    

    If you want to remove all "other" control characters (C0, DEL and C1 control codes), you may use

    .replaceText("\\p{Cc}+", "")
    

    Note that the \v pattern is a construct supported by JavaScript regex engine, and is considered to match a vertical tab character (≡ \013) by the RE2 regex library used in most Google products.

提交回复
热议问题