Rich McCluskey Rich McCluskey - 11 months ago 71
PHP Question

Regex to match words and acronyms in camel case string

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:


... has three capture groups

Some ABC Words

So far I've found this regex:


But that won't handle the acronyms and would just match 'Some' and 'Words'.


One way to solve it is to capture abbreviations with added negative lookahead.


Regular expression visualization