Rich McCluskey Rich McCluskey - 1 year ago 114
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'.

Answer Source

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


Regular expression visualization


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download