谷歌文档脚本,在指定文本中间返回文本值



[当前结果][1] [1]: https://i.stack.imgur.com/O8AGa.png

  • 问题是它们都适用于同一行
  • 我想从同一行单独获取值
  1. 统治

    ▶随机文本◁

    → 仅更改 和 ◁ 之间的▶值

  2. 当前正在使用的脚本


var body = DocumentApp.getActiveDocument().getBody();
var foundElement = body.findText('▶([^S]+)◁');

while (foundElement != null) {
// Get the text object from the element
var foundText = foundElement.getElement().asText();

// Where in the element is the found text?
var start = foundElement.getStartOffset();
var end = foundElement.getEndOffsetInclusive();

// Set Bold
foundText.setBold(start, end, true);
// Change the Foreground color
foundText.setForegroundColor(start, end, "#ff326d");

// Find the next match
foundElement = body.findText('▶([^S]+)◁', foundElement);
}

不完全支持某些正则表达式

根据文档A subset of the JavaScript regular expression features are not fully supported, such as capture groups and mode modifiers.

我建议按照此处的建议在Google问题跟踪器上打开功能请求

最新更新