Search code examples
google-apps-scriptgoogle-sheetsstr-replacereplaceall

replace all numeric characters in google sheets


What better way to replace all numeric characters in google sheets?

I tried the following way but it takes a long time to run and it doesn't look professional:

var caracteres = ["0","1","2","3","4","5","6","7","8","9", ",", "|", ";", ".", "-" ]
  for(c=0; c<caracteres.length; c++){
    sheet.getRange("E:E").createTextFinder(caracteres[c]).replaceAllWith("");

Solution

  • You no longer have to loop so it saves a lot of time.

    function myfunk() {
      const ss = SpreadsheetApp.getActive();
      const sh = ss.getSheetByName("Sheet0");
      sh.getRange("E1:E" + sh.getLastRow()).createTextFinder("[0-9,;|.-]+").useRegularExpression(true).replaceAllWith('');
    }