【发布时间】:2016-03-21 07:58:15
【问题描述】:
我想知道是否可以在 BigQuery 中使用正则表达式从字符串中提取所有数字。
我认为以下方法有效,但只返回第一个命中 - 有没有办法提取所有命中。
我的用例是我基本上想从 url 中获取最大的数字,因为它更像是我需要加入的 post_id。
这是我所说的一个例子:
SELECT
mystr,
REGEXP_EXTRACT(mystr, r'(\d+)') AS nums
FROM
(SELECT 'this is a string with some 666 numbers 999 in it 333' AS mystr),
(SELECT 'just one number 123 in this one ' AS mystr),
(SELECT '99' AS mystr),
(SELECT 'another -2 example 99' AS mystr),
(SELECT 'another-8766 example 99' AS mystr),
(SELECT 'http://somedomain.com/2015/12/this-is-a-post-with-id-in-url-99999' AS mystr),
(SELECT 'http://somedomain.com/2015/12/this-is-a-post-with-id-in-url-99999/gallery/001' AS mystr),
(SELECT 'http://somedomain.com/2015/12/this-is-a-post-with-id-in-url-99999/print-preview' AS mystr)
我从中得到的结果是:
[
{
"mystr": "this is a string with some 666 numbers 999 in it 333",
"nums": "666"
},
{
"mystr": "just one number 123 in this one ",
"nums": "123"
},
{
"mystr": "99",
"nums": "99"
},
{
"mystr": "another -2 example 99",
"nums": "2"
},
{
"mystr": "another-8766 example 99",
"nums": "8766"
},
{
"mystr": "http://somedomain.com/2015/12/this-is-a-post-with-id-in-url-99999",
"nums": "2015"
},
{
"mystr": "http://somedomain.com/2015/12/this-is-a-post-with-id-in-url-99999/gallery/001",
"nums": "2015"
},
{
"mystr": "http://somedomain.com/2015/12/this-is-a-post-with-id-in-url-99999/print-preview",
"nums": "2015"
}
]
【问题讨论】:
标签: regex google-bigquery