How to use RegExReplace in Google Spreadsheet

13,600

Solution 1

I've found another solution for replacing with regexp in Google Docs Script:

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

As I did not find any solution for RegExReplace, I changed the method with replace(regexp, new_text). This one works.

Solution 2

I don't know why the docs list a semicolon, but if you are doing it as a spreadsheet function, you still need to use commas. Try the following:

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

Which as expected, yields

WhatACrazystr3ng

Share:
13,600
conualfy
Author by

conualfy

Updated on August 03, 2022

Comments

  • conualfy
    conualfy almost 2 years

    I'm trying to remove beggining numbers from a column in a Google Docs spreadsheet using regex. I can't get RegExReplace function to work. This is the error I get when I run/debug the code:

    Missing ) after argument list. (line 14)
    

    This is a part of my code (line 14 is the RegExReplace function line, bolded):

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

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

    Anyone knows how to use this function? Thanks!