Say that I have the following string:

```
[AttributeName value1:Foo value2:Bar]

```

AttributeName or valueX aren't important. I can just consider them a sequence of literal or numeric characters.

My question is the following: How can I match `[AttributeName]` as well as 

`[AttributeName value1:Foo value2:Bar]`, but not 

`[AttributeNamevalue1:Foo value2:Bar]`?
 I am fairly new to Regular Expressions, so a bit of detail on the answers would be really nice.

I tried the following:

```
\[ *[a-zA-Z0-9_]+ *([a-zA-Z0-9_]+:[a-zA-Z0-9_]+)*\]

```

Which, to my understanding, matches a string that contains a sequence starting with '[', followed by 0 or more spaces, followed by one or more alphanumeric characters, then again 0 or more spaces. The problem comes here.
If I use `*` to match 0 or more spaces, then `[AttributeNamevalue1:Foo value2:Bar]` will be matched. But if I use `+`, then `[AttributeName]` will not be matched since not followed by a space.
How can I perform an if-then-else kind of check? I've found some sources but none of them explained the matter in a beginner-friendly way.