I need to verify “pathnames” of items stored in localStorage (pathname being a string like: abc/localstorage/ualldocs/aalldocs in order to filter whats in localstorage.
Right now I’m trying this:
priv.localpath = "abc/localstorage/ualldocs/aalldocs";
for (i in localStorage) {
if (localStorage.hasOwnProperty(i)) {
s = new RegExp('\\/' + priv.localpath + '\\/.*$');
if (s.test(i)) {
value = localStorage.getItem(i);
console.log( value );
} else {
console.log( "not found: "+i);
}
}
}
Which does not work = does not find anything.
Question:
How do I create a regex for a string made up of a variable name followed by any character?
But the answer is still the same:
Using the constructor allows this for RegExp