Home > Blockchain >  Google Doc Script for Replacing Text Including Line Breaks
Google Doc Script for Replacing Text Including Line Breaks

Time:01-07

I'm trying to create a Google Docs script function that will replace all the instances of specific text including line breaks with other text that deletes the line break.

I have a long document that I'll be adding to regularly by coping and pasting from other text (I know, not ideal, but I don't have a way to export raw text) and then cleaning it up. In Google Docs I can do a Find and Replace for M\navatar\nM and replace it with M (With the "Match using regular expressions" checked) and then do another find and replace for J\navatar\nJ and replace with J to help with cleanup. I'd like to add these as functions in a script so I can do all the replacements at once. image of google doc find and replace setup

I tried using the replaceText function, but it will not accept the \n expression for the line break and so it finds nothing.

CodePudding user response:

This is just my guess for my understood your question. In your current issue of I tried using the replaceText function, but it will not accept the \n expression for the line break and so it finds nothing., I thought that the reason for this issue might be due to that replaceText cannot be used for multiple paragraphs. If my understanding is correct, I thought that this sample script might be able to be used. enter image description here

To:

enter image description here

References:

  • Related