I have a string, say:
Product Description [White]
I want to extract anything inside the brackets (in this case White
) from that string, using the PostgreSQL Substring function. I can get this to work using regexp_matches
, but that returns an array which I don't want unless I have no other choice.
I've tried:
substring('string' from '[(.)]')
>>> NULLsubstring('string' from '\[(.)\]')
>>> NULLsubstring('string' from '\\[(.)\\]')
>>> NULLBut this works:
substring('string' from 'W(.)i]')
>>> h What am I doing wrong?
(.)
only matches a single character, but you want to match multiple characters in there.
So you need (.+)
substring('Product Description [White]' from '\[(.+)\]')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With