我正在使用google的大查询,我正在尝试找到正则表达式模式,以从用户ID看起来像这样的字符串中提取用户ID:
{"user":"324f65gsaygvsdf54554165sdfsd5"}
完整的字符串看起来像这样:
{"cookie":{"originalMaxAge":null,"expires":null,"httpOnly":true,"path":"/"},"flash":{},"passport":{"user":"324f65gsaygvsdf54554165sdfsd5"},"afterDiscovery":"https://somecompany.com","dashboard":"gbslfdchgddjfgrrgtgjhds5555","authorize":{}}
答案 0 :(得分:1)
将数据显示为json字符串 - 您可以使用JSON
函数代替REGEXP
函数
以下示例适用于BigQuery StandardSQL
#standardSQL
WITH t AS(
SELECT '{"cookie":{"originalMaxAge":null,"expires":null,"httpOnly":true,"path":"/"},"flash":{},"passport":{"user":"324f65gsaygvsdf54554165sdfsd5"},"afterDiscovery":"https://somecompany.com","dashboard":"gbslfdchgddjfgrrgtgjhds5555","authorize":{}}' json
)
SELECT json_extract_scalar(json, '$.passport.user') AS userid
FROM t
答案 1 :(得分:0)
你没有告诉我们太多。例如,您实际使用的是哪种正则表达式引擎:
对于 PCRE ,您可以选择用户ID(根据您的示例,我假设所有字符都是数字或小写字母):
(?<="user":")[a-z1-9]+
(?<="user":")
- 向后看,试图找到&#34; user&#34;:&#34;在实际加工之前(不包括匹配的发现)
[a-z1-9]+
- 匹配至少一个(一对多)小写字符和数字