首页 > 解决方案 > 如何使用正则表达式替换 Google Data Studio 中日期字段的方括号?

问题描述

我正在尝试删除 Google Data Studio 中日期字段周围的方括号,以便我可以正确地将其视为正确的日期维度。

它看起来像这样:

[2020-05-20 00:00:23]

我正在使用 RegExREGEXP_REPLACE(Date, "/[\[\]']+/g", "")并且我希望它的输出看起来像这样:

2020-05-20 00:00:23

它不断给我错误结果并且不起作用。我无法弄清楚我在这里做错了什么,我已经使用https://www.regextester.com/来验证它是否应该工作

标签: regexgoogle-data-studioregexp-replacere2

解决方案


You need to use a plain regex pattern, not a regex literal notation (/.../g).

Note that REGEXP_REPLACE removes all occurrences found, thus, there is no need for a g flag.

Use

REGEXP_REPLACE(Date, "[][]+", "")

to remove all square brackets in Date.


推荐阅读