The script below does not work as intended.
I'm going to search for the sentence that starts with ★ and display it as it is, but I can't do this, so could you please let me know?
For example, I would like to replace the document as follows.
In other words, you want to add a tag.
before replacement:
★ ah jf pew
after substitution:
<div>ajf pew</div>
Current State Script:
function myFunction(){
var doc = DocumentApp.getActiveDocument()
varbody=doc.getBody();
body.replaceText("★.*", '$&');
}
replaceText("★.*", '$&')
I think this will only replace the pattern that starts with ★
with $&
.
I see, String.replace()
of GAS replaces $&
with the entire matched string.I didn't know.
However, DocumentApp.getActiveDocument().getBody().replaceText()
does not seem to have that function.
Then why don't you try it this way?
There might be another problem.
function myFunction(){
var doc = DocumentApp.getActiveDocument();
varbodyText=doc.getBody().getText();
var replacedText=bodyText.replace(/(★\S*)/g, "<div>$&/div>");
doc.getBody().setText(replacedText);
}
581 PHP ssh2_scp_send fails to send files as intended
915 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
572 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
618 Uncaught (inpromise) Error on Electron: An object could not be cloned
© 2024 OneMinuteCode. All rights reserved.