简体   繁体   English

获取字符串中出现的所有 substring

[英]Getting all the occurrences of a substring within a string

How can I get all the occurrences of a substring within a string in PostgreSQL?如何获取 PostgreSQL 中字符串中出现的所有 substring?

I have this string for an ID:我有一个 ID 字符串:

BS Score xxxxxxx075SCxxxBS Score xxxxxxx062SCxxxBS Score xxxxxxx115SCxxx

And I would like to get the numbers in the string for the ID, so the result can look like this:我想获取 ID 字符串中的数字,因此结果如下所示:

在此处输入图像描述

You can use regexp_matches :您可以使用regexp_matches

select id intl, regexp_replace(v[1], '^0+', '') values from tbl 
cross join regexp_matches(id, '(\d+)', 'g') v

See fiddle .见小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM