A
A
Anton Zolotarev2021-04-29 11:50:38
Regular Expressions
Anton Zolotarev, 2021-04-29 11:50:38

How to make the regular in google apps script in spreadsheets replace not the first match found, but all?

I know about the global flag, but it doesn't work for some reason. Maybe I'm doing something wrong...

function myFunction() {
  phone="097-888-88-88";
  phone = phone.replace('-', '', 'g')
  Logger.log(phone);
}

UDP
worked like this
var regex = new RegExp('-', 'g');
phone = phone.replace(regex, '', 'g');


608a7339d661c808957594.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
toxa82, 2021-04-29
@antonzol

phone = phone.replace(/-/g, '');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question