How to use RegExReplace in Google Spreadsheet

I am trying to remove seed numbers from a column in a Google Docs spreadsheet using regex. I cannot get RegExReplace to work. This is the error I get when running / debugging the code:

Missing ) after argument list. (line 14) 

This is part of my code (line 14 is the RegExReplace function line in bold):

 regexFormat = "^[0-9]+$"; replVal = value.RegExReplace(value; regexFormat; ""); //error here rplc.setValue(replVal); 

This is the official syntax: RegExReplace( text ; regular_expression ; replacement )

Does anyone know how to use this feature? Thanks!

+7
source share
3 answers

I found another replacement solution using regex in Google Script Docs:

 var replace = '';//because we want to remove matching text var regexp2 = new RegExp("[0-9]*[\.]*");//an example of regexp to do the job var valcurat = value.replace(regexp2, replace);//working 

Since I did not find a solution for RegExReplace, I changed the method with a replacement (regexp, new_text). It works.

+2
source

I don’t know why there is a semicolon in the list of documents, but if you do this as a function of a spreadsheet, you still need to use commas. Try the following:

=REGEXREPLACE("What-A Crazy str3ng", "\W", "")

What, as expected, gives

WhatACrazystr3ng

+4
source

This is just an assumption, but if the Javaish function, there are probably two forms.
Form 1:
myvar = RegExReplace(value; regexFormat; "");
Form2:
myvar = value.RegExReplace(regexFormat; "");

0
source

All Articles