在 google 个工作表中提取 first/second/third 个包含 X 的单词

Extract first/second/third word containing X in google sheets

是否可以提取 google sheet 中包含 X 的句子中的文本片段。在通过 Apps 脚本的公式中。我在 google 上找不到合适的答案,或者不知道要搜索什么。

例如:

A1:[Peter]将[球]踢给[Shaun]。

我想在 B1 中提取第一个包含 '[' & ']' 的词,在 C1 中提取第二个包含 '[' & ']' 的词,等等。

所以:

A B C D
[Peter] kicks the [ball] to [Shaun]. [Peter] [ball] [Shaun]

试试这个

=regexextract(A1,regexreplace(regexreplace(A1,"[\[]","(\\["),"[\]]","\\])"))

正在提取单词并将其发布到 sheet

function lfunko() {
  const ss = SpreadsheetApp.getActive();
  const sh = ss.getSheetByName("Sheet0");
  let a = sh.getRange("A1").getValue();
  let o = a.toString().match(/\[[A-Za-z]+\]/g).map(e => e);
  sh.getRange(1, 2, 1, o.length).setValues([o]);
  console.log(JSON.stringify(a));
}

希托:

A B C D
[Peter] kicks the [ball] ot [Shaun]. [Peter] [ball] [Shaun]