我正在尝试从URL中获取哈希的第一部分(在#和/、?或字符串结尾之间的部分)。
到目前为止,我得出了以下结果:
r = /#(.*)[\?|\/|$]/
// OK
r.exec('http://localhost/item.html#hash/sub')
["#hash/", "hash"]
// OK
r.exec('http://localhost/item.html#hash?sub')
["#hash?", "hash"]
// WAT?
r.exec('http://localhost/item.html#hash')
null
我原本期望收到“哈希”。
我追踪问题到了。
/#(.*)[$]/
r2.exec('http://localhost/item.html#hash')
null
任何想法是什么出了问题?