V
V
Vladimir Zuev2020-06-06 16:07:23
Google Sheets
Vladimir Zuev, 2020-06-06 16:07:23

How to write regular expressions in google sheets?

Hello.
And how to write regular expressions for google api?
I process the addresses that came from Prom ua.
The main address formats are

Стрый, № 3 (до 30 кг): ул. Почтовая, 5
Приколотное, №1: ул. Центральная, 32
Черкассы, Отделение №9 (до 30 кг): ул. Остафия Дашкевича, 34
Глеваха, №1: ул. Вокзальная, 11
Киев, №189 (до 30 кг): ул. Ялтинская, 24/23
Кучурган, №1: ул. Павла Каплуна, 71
Днепр
Ахтырка, №3 (до 30 кг на одно место): ул. Армейская (ран. Красноармейская), 89б

Wrote a regular
/(\w+)(,\s(.*[№]\s?\d+)(\s\((.+)\))?:\s(.+))?/
program On the site regex101.com. Everything shows well
When I enter into the code
var address = orderList["orders"][i]['delivery_address'];
              
              const matches = address.match(/(\w+)(,\s(.*[№]\s?\d+)(\s\((.+)\))?:\s(.+))?/);
             Logger.log('address=',address); 
              Logger.log('matches=',matches); 
              if(matches!==null){
                           for (let u = 1; u <= 4; u++) {
                               Logger.log(matches[u]);
                               //Logger.log(orderList); 
                             }

It turns out God knows what. The program generally flew to the icon at the beginning of the line. What am I doing wrong. Please help.
How to write a regular expression for google sheets.
I can upload screenshots with the results.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Grigory Boev, 2020-06-06
@vladd56

You may need to specify flags in a regular expression ( gmi ). If there is no g flag, . match () returns only the first match as an array, where the match is at index 0.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question