在我的扩展中,我想获得href
属性a
对象,它是/photo123456789_987654321
。我如何解决Chrome扩展中的Slash问题?
但取而代之,我得到chrome-extension://extension-id/photo123456789_987654321
。
我该如何解决这个问题?
在我的扩展中,我想获得href
属性a
对象,它是/photo123456789_987654321
。我如何解决Chrome扩展中的Slash问题?
但取而代之,我得到chrome-extension://extension-id/photo123456789_987654321
。
我该如何解决这个问题?
怎么样用正则表达式替换扩展ID:
href_string.replace(/^chrome-extension:\/\/.*?\//, "/");
例如
var href_string = "chrome-extension://extension-id/photo123456789_987654321";
href_string.replace(/^chrome-extension:\/\/.*?\//, "/");
// "/photo123456789_987654321"
而不是使用一个更复杂的正则表达式,你可以只使用字符串的第一部分:
var someString = "chrome-extension://extension-id/photo123456789_987654321";
someString.replace("chrome-extension://extension-id","");
感谢。点在你的正则表达式中意味着什么? (之前*?) – DrStrangeLove
@DrStrangeLove:它表示'任何字符',所以'。*?'表示:一个或多个任何字符,但不会太多('。*'会导致'extension-id/a/b '用'/ b'替换)。 – pimvdb