Google 文档 - 删除段落结尾处多余的 space 个字符

Google Documents - remove redundant space charachters at paragraph endings

我正在尝试使用 GAS 从段落结尾删除多余的 space 个字符。

如何实现?

例子:

This is sentence 1 in paragraph 1. This is sentence 2 in paragraph 1 
This is paragraph 2 (more text...)

“...第 1 段中的句子 2”后有一个 space 字符。 (即“......第 1 段中的句子 2</code>”。 我想用代码摆脱它。</p> <p><strong>到目前为止我试过了</strong>:</p> <pre><code> paragraphs[i].replaceText(/\h\r/g,"\r");

其中 paragraphs[i] 是我正在检查的段落(遍历文档正文中的所有段落)。

出现这个错误:

Exception: Invalid regular expression pattern /\h\r/g

我承认我对正则表达式有非常基本的了解。

尝试

paragraphs[i].replaceText("\s+$","");// double `\` is intentional
  • \ss速度
  • $: 字符串结束