Question: So I have a string that can be either:

```
aa -- bb -- cc -- dd

```

or

```
aa -- bb -- cc -- dd -- ee

```

aa,bb,cc,dd,ee can be any character (except the delimiter which is ' -- ')

This is what I've tried:

```
(.*?) -- (.*?) -- (.*?) -- (.*)((.*?)|)

```

It almost works. It can capture the first but not the second one correctly.

I have to use capturing groups and capture strings between delimiters. Only matching is not enough.

So capture groups should be 

aa
bb
cc
dd 

OR

aa
bb
cc
dd
ee

Answer: 
If you have to go the regex way, I would use `^(\\S+) -- (\\S+) -- (\\S+) -- (\\S+)(?: -- (\\S*))?$`, capturing your content into 4 or 5 capturing groups.

I used the \S to avoid unnecessary expansion with the lazy matching, which will speed up the regex a bit. I also added anchors for start and end, as it seems you want to match a whole string.

Note: I'm not sure, how java handles capturing group repetition, in most regex flavours constructs like `(.){4}` will only capture the last repetition.
Make the last term *optional*:

```
(\S+) -- (\S+) -- (\S+) -- (\S+)(?: -- (\S+))?

```

I also changed to using `\S+` to avoid false positives for missing terms or badly formatted input.

Note also the use of a *non-capturing* group so the fifth (optional) term is in group 5 (instead of group 6).