I would like to know the regular expression for c# fulfill the following pattern:

* only allow numbers, comma and digit
* must start and end with digit
* range of digit is 0 to 999
* digits (e.g. 1,2,3) or range (e.g. 1-3, 2-5) are separated by ','
* between two ',' must be a digit or range
* '-' must start and end with digit
* Allow only 0-1 white space after ','

**Example:**

```
1-100,134,200 --> PASS. Maximum range of numbers 0-999
1,18,100      --> PASS
1, 18, 100    --> PASS. Allow 0-1 white space after ',' 
1,  18,100    --> FAIL. Due to more than 1 white space after ','
1-,18,100     --> FAIL. Due to no digit after '-'
-2,18,100     --> FAIL. Due to no digit before '-'
1,,18,100     --> FAIL. Due to no digit between ','
1, ,18,100    --> FAIL. Due to no digit between ','
,2,18,100     --> FAIL. Due to no digit before ','
1,18,100,     --> FAIL. Due to no digit after ','

```

I tried using the following code but it always return a true result:

```
string pattern = @"[0-9]+(?:-[0-9]+)?(,[0-9]+(?:-[0-9]+)?)*";
string test = @"1-5,13,238,-a";
bool result = Regex.IsMatch(test, pattern);

```