Replacing a paragraph break with something else in a Google Doc can be done via the "Find and Replace..." dialog box, using \n
as a search pattern, with regular expressions enabled.
The same pattern, however, does not work in a Google Apps Script:
body = DocumentApp.getActiveDocument().getBody();
// note that escaping the backslash is required
body.replaceText("\\n", "EOL"); //matches nothing
even though:
body.replaceText("\\v", "EOL"); //matches "soft returns"
body.replaceText("\\s", "EOL"); //matches whitespace
The official reference is very terse, other than warning of the need to escape the backslashes.
It is obviously possible to solve the problem programmatically (see for example my own answer here), but does anyone know how to write a regular expression pattern that can be used as an argument in replaceText()
and that matches a paragraph break?