Question: I'm trying to return a comma separated string without the items that end in 'non'.

Source:

```
id = '2345,45678,3333non,489,2333non';  

```

Expected Result:

```
id = '2345,45678,489'; 

```

I'm using code that I found here: 
[remove value from comma separated values string](https://stackoverflow.com/questions/1306164/remove-value-from-comma-separated-values-string)

```
var removeValue = function(list, value, separator) {
  separator = separator || ",";
  var values = list.split(separator);
  for (var i = 0; i < values.length; i++) {
    if (values[i] == value) {
      values.splice(i, 1);
      return values.join(separator);
    }
  }
  return list;
}

```

Is there a way to make the line `(values[i] == value)` use a wildcard?

Answer: 
Use `/[^,]*non,|,[^,]*non/g`:

```js
id = '2345,45678,3333non,489,2333non';

console.log(
  id.replace(/[^,]*non,|,[^,]*non/g, '')
)
```

---

As a function:

```js
id = '2345,45678,3333non,489,2333non';

removeItem = function(s, ends) {
  pat = new RegExp(`[^,]*${ends},|,[^,]*${ends}`, 'g')
  return s.replace(pat, '')
}

console.log(removeItem(id, 'non'))
```
You don't need regex for this. Just split on `,` and filter the array for all elements that don't end in `non`.

```js
var id = '2345,45678,3333non,489,2333non'
console.log(id.split(',').filter(x => !x.endsWith('non')).join(','))
```

Thanks to [Nope](https://stackoverflow.com/users/448144/nope) for pointing out that `endsWith()` will not work in IE. To get around this issue, see [Mozilla's Polyfill for `endsWith`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith#Polyfill) or [JavaScript endsWith is not working in IEv10](https://stackoverflow.com/questions/37544376/javascript-endswith-is-not-working-in-iev10/37545037).