简体   繁体   中英

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)
  2. Paris, France (BR10293)
  3. (BR62543) Spice girls (BR6729)

I need to have following column

  1. BR20134
  2. BR10293
  3. 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.

Thanks

This always extracts the last parenthesized expression:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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