I've went through so many posts about this but can't find one that works. I have object keys that I want to search through and see if they have either of two specific words in them and filter them if the exist.
Example:
const obj = {
time_pop: 'fhfvla',
icon: 'dsfval',
home_pops: 'valffg',
title: 'sdfsdfs',
pop: 'sfsdfsd',
rattle: 'sdfdsf',
pops: 'sfsdfsdf'
}
I want a regex that can find either the word pop || pops in object keys. I'm currently looping through and have the key and am using this as my regex
const expr = /\b(pop|pops)\b/;
const only = Object.entries(obj).filter(([k, v]) => {
return expr.test(k);
})
The above only works for one word not if it has a _ in it. For example this is not working. time_pop home_pops
They are return false when they should return true because the word pop or pops is in them.