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" ]

```
A perl way to do the job:

```
use Modern::Perl;

my $in = '4,d,e,1,2,3,4,a,b,c,d,e,f,a,b,c,1,2,3,c,b,a,2,3,1,';
my (%h, @r);
for (split',',$in) {
    push @r, $_ unless exists $h{$_};
    $h{$_} = 1;
}
say join',',@r;

```

**Output:**

```
4,d,e,1,2,3,a,b,c,f

```