Question: I have this string `ActionComedySci-Fi` and I want to separate it into an array like `["Action", "Comedy", "Sci-Fi"]` but the string could also be `ActionComedyThriller` which doesn't have a hyphen and those words could be in any order.

So my question is: How can I use Node.JS to split strings by their capital letters and include them in the same array column even if they have a hyphen?

I have tried using `"ActionComedySci-Fi".split(' ')[0].match(/[A-Z]*[^A-Z]+/g);` but that just returns `["Action", "Comedy", "Sci-", "Fi"];`

Answer: 
Rather that `split` you can use `match` using this lookahead regex:

```
/([A-Z].*?[a-z])(?=[A-Z]|$)/gm

```

`([A-Z].*?[a-z])` will match from an uppercase letter to lowercase letter.

**Code:**

```
var re = /([A-Z].*?[a-z])(?=[A-Z]|$)/gm

var s = 'ActionComedySci-Fi'    
var m = s.match(re)
//=> ["Action", "Comedy", "Sci-Fi"]

s = 'ActionComedyThriller'    
m = s.match(re)
//=> ["Action", "Comedy", "Thriller"]

```
Since you didn't specify whether whitespace lies between the word, you could possibly split using a non-word boundary while asserting that a character in the range "A" to "Z" follows:

```
'ActionComedySci-Fi'.split(/\B(?=[A-Z])/);    //=> [ 'Action', 'Comedy', 'Sci-Fi' ]
'ActionComedyThriller'.split(/\B(?=[A-Z])/);  //=> [ 'Action', 'Comedy', 'Thriller' ]

```

If the `split` method is acting up on you, simply match the pattern instead:

```
var r = s.match(/[A-Z][a-z]+(?:-[A-Z][a-z]+)?/g)

```