Reputation: 3802
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
Upvotes: 2
Views: 2495
Reputation: 4395
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'
.
Upvotes: 9