谷歌脚本。获取包含部分字符串的数组

问题描述 投票:0回答:1

我有一个电子表格,其中 1 个单元格中有以下链接:

https://drive.google.com/open?id=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, https://drive.google.com/open?id=yyyyyyyyyyyyyyyyyyyyyyyyyyyyyy

我需要 X 部分和 Y 部分的数组。

body.editAsText().appendText(myimage.match(/[\w\_\-]{33,}/).toString());

body.editAsText().appendText(myimage[0]);
body.editAsText().appendText(myimage[1]);

这两条线都带来同一条线xxxxxx.....

string google-apps-script text lookup
1个回答
0
投票
function myfunk01() {
  const ss = SpreadsheetApp.getActive();
  const sh = ss.getSheetByName("Sheet0");
  const v = sh.getRange("A1").getDisplayValue();//https://drive.google.com/open?id=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, https://drive.google.com/open?id=yyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
  const arr = v.split(',').map((e => e.trim().split("=")[1]));
  Logger.log(JSON.stringify(arr))
}

Execution log
7:05:28 PM  Notice  Execution started
7:05:29 PM  Info    ["xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","yyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"]
7:05:30 PM  Notice  Execution completed
© www.soinside.com 2019 - 2024. All rights reserved.