经过一番挖掘,我最终得到了这个解决方案:
SELECT mystr, GROUP_CONCAT(SPLIT(REGEXP_REPLACE(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)
这个怎么运作:
我首先使用正则表达式来匹配任何非数字并用逗号替换
然后split
用来得到结果,空结果被丢弃
group_concat
就是在这里展示结果