我有一个string.replace()
函数,该函数使用正则表达式向后移动。
myString.replace(/(?<!\\)'/gi, '"')
但是我发现此功能目前对浏览器的支持有限。https://caniuse.com/#feat=js-regexp-lookbehind
是否可以使用javascript测试用户浏览器对此功能的支持?
类似于CSS.supports()
功能?
创建这样的测试并不难:
function supportsLookbehind(input, expected) {
try {
return input.replace(/(?<!\\)'/gi, '"') === expected;
} catch (err) {
//handle error
}
return false; //If it reaches here, it's not working as expected
}