regexp_substr 字符串中的数字比率

regexp_substr a numeric ratio within a string

如何利用 regexp_substr 函数(在 redshift 中)从字符串中提取数字比率?示例:

Product name 1:4 subtype name
10:5 product name
[5:1] product name
product name [1:15]

只想捕获文本的 1:4 部分。

谢谢

您可以像这样使用 regexp_substr()

regexp_substr(mycol, '[0-9]+:[0-9]+')

这会提取模式的(第一个)匹配项,前提是至少有一个数字,后跟一个分号,然后是至少一个数字。