I am validating a string with a regex, PCRE flavor. I have a substring that can optionally appear in one of two possible places - but not both. How do I write a regex for that? 

The regex without the substring is 

```
M[01]([ ]*\(?[A-Z]{3}\)?)?

```

The substring has the regex C[0-5] and can come either before or after the parentheses, or not be present at all. It can be separated by whitespace or not. 

Valid examples (all including whitespace for legibility, but the same ones without whitespace are also valid): 

```
M1
M1 C1
M1 (OSS)
M1 C1 (OSS)
M1 (OSS) C1

```

Invalid examples: 

```
M1 C1 (OSS) C1

```

The closest thing I came up with is 

```
M[01]([ ]*C[1-5]?)([ ]*\(?[A-Z]{3}\)?)?([ ]*C[1-5]?)

```

but this will also accept the invalid example. Since I only have two positions, I could of course enumerate the different combinations, but I dislike that solution because it does not scale well to more possible positions. 

If that matters, this is a group that will be present in a longer string to be validated, so the regex will be embedded in a larger one as a subroutine.