Google Spreadsheet API setDataValidation with Regex

[亡魂溺海] 提交于 2021-01-29 09:59:51

问题


Im trying to generate an Google Spreadsheet Template with some Validation with their API, using the Node.Js Package from Google.

This is my current Request:

{
 "setDataValidation": {
    "range": {
      "sheetId": 1656514345,
      "startRowIndex": 0,
      "endRowIndex": 0,
      "startColumnIndex": 1,
      "endColumnIndex": 1000
    },
    "rule": {
      "condition": {
        "type": "CUSTOM_FORMULA",
        "values": [
          {
            "userEnteredValue": "=REGEXMATCH(TO_TEXT(A2:A1000); '([1-9]){4}[-]([1-9]){2}[-]([1-9]){2}$')"
          }
        ]
      },
      "inputMessage": "TEST VALIDATION",
      "strict": true
    }
  }

}

I get the following Error:

Error: Invalid requests[0].setDataValidation: Invalid ConditionValue.userEnteredValue: =REGEXMATCH(TO_TEXT(A2:A1000); '([1-9]){4}[-]([1-9]){2}[-]([1-9]){2}$')

A simple create or append Data in the Spreadsheet works fine, but getting an Regex Validation to work seems like the limit. In the Documentation there seems no limitation for RegEx, what is wrong with my Request?

Thanks in Advance.


回答1:


Your expression needs to be escaped.

"userEnteredValue": "=REGEXMATCH(TO_TEXT(A1), \"[0-9]{4}[-][0-9]{2}[-][0-9]{2}$\")"

Note that the internal quotes are escaped (\" instead of ").

Note that single quotes also won't work.



来源:https://stackoverflow.com/questions/58977942/google-spreadsheet-api-setdatavalidation-with-regex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!