Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use RegExReplace in Google Spreadsheet

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!

like image 245
conualfy Avatar asked Nov 17 '11 23:11

conualfy


2 Answers

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

like image 109
radicand Avatar answered Oct 30 '22 13:10

radicand


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.

like image 42
conualfy Avatar answered Oct 30 '22 11:10

conualfy