Regex = Comment Remplacer le caractère speciale "+" (plus) par un retour à la ligne

31 views
Skip to first unread message

Lapiaute

unread,
Sep 28, 2022, 4:15:04 AMSep 28
to Google Apps Script Community
Bonjour,

Comment remplacer un méta caractère dans un Google document 
Apps script
J'ai essayé avec le caractère d'échappement  "\u002B"  "\+" sans réussite

Dans mon document actuel :

Chat + Chien + Cheval

Résultat souhaité

Chat 
Chien 
Cheval

=========

function regexTestFunction(){

const document = DocumentApp.getActiveDocument();
const documentBody = document;
const keyWord = "+"; // Je n'arrive pas à remplacer le caractère speciale "+" (plus) "\u002B" par un retour à la ligne
var replace = `${keyWord}`;
var re = new RegExp(replace, "gm");
documentBody.setText(documentBody.getText().replace(re,'\u000D'));

// \\ The backslash character<br>
//\t The tab character ('\u0009')<br>
//\n The newline (line feed) character ('\u000A')<br>
//\r The carriage-return character ('\u000D')<br>
//\f The form-feed character ('\u000C')<br>
//\a The alert (bell) character ('\u0007')<br>
//\e The escape character ('\u001B')<br>
//\cx The control character corresponding to x <br>

}
==========

Andrew Roberts

unread,
Sep 28, 2022, 5:49:43 AMSep 28
to google-apps-sc...@googlegroups.com
Try 

function replace() {
DocumentApp.getActiveDocument().getBody().replaceText(" \\+ ", "\n")
}

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/21c659f9-8a25-44f5-9c82-1dc1a961e997n%40googlegroups.com.

Lapiaute

unread,
Sep 28, 2022, 6:16:52 AMSep 28
to Google Apps Script Community
Thanks Roberts 🔥
Works very well


Is it possible to have in my google documented list  in my Google Document ?


I obtain this
  1. NEISVAC
MMRVAXPRO
ZYMADUO 150
DOLIPRANE



I would obtain 
  1. NEISVAC
  2. MMRVAXPRO
  3. ZYMADUO 150
  4. DOLIPRANE

===========
==========

NOM Prenom

24 Ans

Le 27/09/2022




QSP 28 Jours

OAR  2 fois 
    Votre Traitement se termine le -> 20/12/2022
    Prendre votre Prochain RDV 15 Jours plus tôt soit à partir du 06/12/2022




  1. NEISVAC
MMRVAXPRO
ZYMADUO 150
DOLIPRANE

===========
==========

Andrew Roberts

unread,
Sep 28, 2022, 7:13:41 AMSep 28
to google-apps-sc...@googlegroups.com

Lapiaute

unread,
Sep 30, 2022, 6:20:07 AMSep 30
to Google Apps Script Community

Please help 
Sorry Robert but I can't insert this function in my script

function changeReturnCariage(){

const document = DocumentApp.getActiveDocument();
const documentBody = document;

// insertListItem(childIndex, text)     i don't find the correct syntax

DocumentApp.getActiveDocument().getBody().replaceText(" \\+ ", "\n")

Cdlt 
Laurent

// DocumentApp.getActiveDocument().getBody().insertListItem("\n","" )
// const keyWord = "\u002B"; // Je n'arrive pas à remplacer le caractère speciale "+" (plus) \u002B par un retour à la ligne
//var replace = `${keyWord}`;
//var re = new RegExp(replace, "gm");
//+ str.replace(/([-])+/g, "");
//=REGEXREPLACE(A1,"[""|+|=]"," ")
// documentBody.setText(documentBody.getText().replace('[\+]','\u000D'));
// DocumentApp.getActiveDocument().getBody().replaceText(" \\+ ", "\n")
// documentBody.setText(documentBody.getText().replace(re,'\u000D'));

// \\ The backslash character<br>
//\t The tab character ('\u0009')<br>
//\n The newline (line feed) character ('\u000A')<br>
//\r The carriage-return character ('\u000D')<br>
//\f The form-feed character ('\u000C')<br>
//\a The alert (bell) character ('\u0007')<br>
//\e The escape character ('\u001B')<br>
//\cx The control character corresponding to x <br>

}
Reply all
Reply to author
Forward
0 new messages