我需要验证存储在 localStorage 中的项目的“路径名”(路径名string
类似于:abc/localstorage/ualldocs/aalldocs
为了过滤 localstorage 中的内容。
现在我正在尝试这个:
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);
}
}
}
哪个不起作用=找不到任何东西。
问题:
如何为由变量名后跟任何字符组成的字符串创建正则表达式?