Question: I have a string

`CO12dadaCO2dafdCO345daaf`

I want to extract all occurences of CO followed by some digits `/CO(\d*)([\s\S]*)/`, up to another CO.

In this case I want to get the output:

`['CO12dada', 'CO2dafd', 'CO345daaf']`

The above regex I tried also matches the rest of the CO's at once so it doesn't work.

I could get the index of a regex for the first match using `str.search`, but I need the indexes of a regex for all occurrences.

Answer: 
```js
const string = 'CO12dadaCO2dafdCO345daaf'
const result = string.match(/(CO.*?)(?=CO|$)/g)
console.log(result)
```
Using Javascript, you can use

```
CO[^]*?(?=CO|$)

```

* `CO[^]*?` Match CO, then any char including newlines as least as possible
* `(?=CO|$)` Positive lookahead, assert what is on the right is either CO or the end of the string

[REgex demo](https://regex101.com/r/BdJQYc/1)