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: 
Code
----

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

```

Explanation
-----------

* `^` Assert position at beginning of the line
* `(?:-?\d+ )*` Match the following any number of times
	+ `-?\d+` Match zero or one of the `-` character, followed by one or more digits, followed by a space character
* `(?:-?\d+)+` Match zero or one of the `-` character, followed by one or more digits
* `$` Assert position at the end of the line
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$ 

```