Question: Trying to find a regex for a string containing only numbers and single spaces (but no spaces at beginning and end) such as this:

"1 2 3 -4" --> Accept

" 1 2 3 -4 " --> Not accept

So far been using this:

```
^\S+[-?\d ]*\b$

```

However this still accepts the string for:

"1 2 --3" which should not be accepted due to a double negative and a double space.

Note that the numbers can be any integer. 

Any help?

Thank you

Answer: 
This will work:

```
^-?\d+(?:[ ]-?\d+)*$

```

Note that

* the `+` quantifier is applied only to the `\d` expressions.
* I put the required single-space separator into a character class for clarity; it could equivalently be expressed without
* the anchors aren't really necessary if you are going to use `Matcher.matches()` to match single-line strings.
Try this: 

```
^\S+( (-?)[\d]+)+\b$

```

or even better:

```
^\S+( ((-?)\d+))+\b$|^\d$

```

in order to match single digits also

Edit (see comments):

This should be an even better version (removes that leading \S)

```
^\d( (-?)[\d]+)*\b$ 

```