regex: filter out certain words AND also a word where a part changes depending on user

Viewed 21

I am trying to construct a regex that filters out certain words. That I was thinking of doing with the below regex:

/^(source-compliance|i18nextLng|userToken)$/.test(str);

However, an new value needs to be added. We have for example 'pinned-homepage-46488645' the number part is an example of a user-id, so it's never the same number. How can I add pinned-homepage + followed by number to this regex?

1 Answers

You need to escape - by using \ in your regex expression.

var str ='pinned-homepage-46488645';
var result =/^(source-compliance|i18nextLng|userToken|pinned\-homepage\-\d+)$/.test(str);
console.log(result);

Related