I encountered a case where I need to split String
per word that is in camel case. I'm implementing the split process similar to the answer this question using this pattern:
split(/(?=[A-Z])/)
Everything is fine until I encountered this test set:
- SalaryGrade - Salary Grade
- ParentChild - Parent Child
- Maintenance - Maintenance
- RemittanceSPD - Remittance S P D
- FBIAgent - F B I Agent
- FBIAgentNYDepartment - F B I Agent N Y Department
One up to three works fine, but four to six should be "Remittance SPD", "FBI Agent", "FBI Agent NY Department" respectively.
How can I select the regions in such a way that it will treat successive upper case letter as one word and the last of the sequence as the start of the next word? I'm not that fond of one-liner Regex to be honest and I'm losing all hope. I'm planning to perform a brute force loop here, if not only about that performance.
EDIT: I want both words with non-succeeding uppercase letters and those with succeeding uppercase letters to be satisfied with this function, unlike the other questions about splitting strings here on this site.