Reputation: 2011
I need a regular expression to capture the word parts of a string that is camel case and might have an acronym in it. In other words, I want to split a camel case string into its words and acronyms.
For example:
SomeABCWords
... has three capture groups
Some ABC Words
So far I've found this regex:
((?:^|[A-Z])[a-z]+)
But that won't handle the acronyms and would just match 'Some' and 'Words'.
Upvotes: 1
Views: 1108
Reputation: 4027
This regex should work, at least for the case you posted :
[A-Z][a-z]+|[A-Z]*(?![a-z])
Upvotes: 0
Reputation: 12807
One way to solve it is to capture abbreviations with added negative lookahead.
[A-Z][a-z]+|[A-Z]+(?![a-z])
Upvotes: 3