简体   繁体   English

如何提取Postgresql中最后两个括号之间的数据?

[英]How to extract the data between the last two brackets in Postgresql?

So for example I have the following column:因此,例如我有以下列:

  1. Hello this is (BR20134)你好,这是 (BR20134)
  2. Paris, France (BR10293)法国巴黎 (BR10293)
  3. (BR62543) Spice girls (BR6729) (BR62543) 辣妹 (BR6729)

I need to have following column我需要有以下列

  1. BR20134 BR20134
  2. BR10293 BR10293
  3. BR6729 BR6729

I am using this query to extract what's between columns:我正在使用此查询来提取列之间的内容:

select substring(Column FROM '\((BR.+)\)')
FROM Table

but obviously it only works if there is one pair of brackets in a field and not two.但显然它只有在一个字段中有一对括号而不是两个时才有效。

I am using Postgresql btw.我正在使用 Postgresql 顺便说一下。

Thanks谢谢

This always extracts the last parenthesized expression:这总是提取最后一个带括号的表达式:

substring(textcolumn FROM '\((BR[^)]+)\)[^(]*$')

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

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