Google Docs 脚本,返回指定文本中间的文本值

问题描述

[当前结果][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,"#ff326d");
 
   // Find the next match
   foundElement = body.findText('▶([^\S]+)◁',foundElement);
}


解决方法

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

根据 documentation 2021/05/31 15:21:45 warn can't create table 'Data.Calls': <nil>,will try again 2021/05/31 15:21:45 warn can't create table 'Data.Fcst_1': <nil>,will try again 2021/05/31 15:21:45 warn can't create table 'Data.Fcst_3': <nil>,will try again 2021/05/31 15:21:45 warn can't create table 'Data.GAInfo': <nil>,will try again 2021/05/31 15:21:45 warn can't create table 'Data.HistoryLogs': <nil>,will try again 2021/05/31 15:21:45 warn can't create table 'Data.Info': <nil>,will try again 2021/05/31 15:21:45 warn can't create table 'Data.Info1': <nil>,will try again 2021/05/31 15:21:45 warn can't create table 'Data.Info15': <nil>,will try again 2021/05/31 15:21:45 warn can't create table 'Data.Info548': <nil>,will try again 2021/05/31 15:21:45 warn can't create table 'Data.Info60': <nil>,will try again 2021/05/31 15:21:45 warn can't create table 'Data.InfoAXPNew': <nil>,will try again 2021/05/31 15:21:45 warn can't create table 'Data.InfoAXPOld': <nil>,will try again 2021/05/31 15:21:45 warn can't create table 'Data.InfoPageView': <nil>,will try again

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