Question: I have following string

1,2,3,a,b,c,a,b,c,1,2,3,c,b,a,2,3,1,

I would like to get only the first occurrence of any number without changing the order. This would be

1,2,3,a,b,c,

With this regex (found @ <https://stackoverflow.com/a/29480898/9307482>) I can find them, but only the last occurrences. And this reverses the order.

`(\w)(?!.*?\1)` (<https://regex101.com/r/3fqpu9/1>)

It doesn't matter if the regex ignores the comma. The order is important.

Answer: 
Regular expression is not meant for that purpose. You will need to use an index filter or Set on array of characters.

Since you don't have a language specified I assume you are using javascript.

Example modified from: <https://stackoverflow.com/a/14438954/1456201>

```js
String.prototype.uniqueChars = function() {
    return [...new Set(this)];
}

var unique = "1,2,3,a,b,c,a,b,c,1,2,3,c,b,a,2,3,1,".split(",").join('').uniqueChars();
console.log(unique); // Array(6) [ "1", "2", "3", "a", "b", "c" ]

```
I would use something like this: 

```
// each index represents one digit: 0-9
const digits = new Array(10);

// make your string an array
const arr = '123abcabc123cba231'.split('');

// test for digit
var reg = new RegExp('^[0-9]$');

arr.forEach((val, index) => {
  if (reg.test(val) && !reg.test(digits[val])) {
    digits[val] = index;
  }
});

console.log(`occurrences: ${digits}`); // [,0,1,2,,,,....]

```

To interpret, for the digits array, since you have nothing in the 0 index you know you have zero occurrences of zero. Since you have a zero in the 1 index, you know that your first one appears in the first character of your string (index zero for array). Two appears in index 1 and so on..