I want to return all characters before the 2nd occurrence of the character slash '/' (if any) in PostgreSQL.
Input Column:
/apple/orange/banana
/
/mango
/avocado/kiwi
Desired Output Column:
/apple
/
/mango
/avocado
Can anyone help with this please?
One method is regexp_replace():
select t.*,
regexp_replace(col, '^([^/]*/[^/]*)/.*$', '\1')
from t;
Here is a db<>fiddle.
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