Trying to get a regex to recognize and extract words from both camelCase and CamelCase

I’ve got this halfway working. This works great:



["My", "Own", "Var"]

The goal is to pull out the individual words. But if I pass a camelCase name to it:


I get:

["myOwn", "Var"]

I can’t figure out what I’m doing wrong. As far as I can tell, two sets of () should store the matching results in two separate array elements. It’s lumping them in together for some reason.

Source: regex

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.