I have sene Split words with a capital letter in sql which is applicable to MS SQL but I was wondering how to achieve the same using PostgreSQL
Basically I'm getting values such as FirstNameValue but I need it to be First Name Value
Unfortunately I don't know where to even start. I got to the following and got stuck straight away
SELECT REGEXP_REPLACE('ThoMasTest', '[^ ][A-Z].', ' ')
The result from a string such as ThoMasTest should be Tho Mas Test
Thanks
This should do the trick:
select regexp_replace('ThoMasTest', '([a-z])([A-Z])', '\1 \2','g');
The expression matches two characters next to eachother, each one in its own group:
[a-z] that matches a lowercase letter.[A-Z] finds a capital letterSo if one lowercase if immediately followed by a capital letter insert a space between them.
Do that globally 'g'.
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