我正在浏览twitter bootstrap的代码,并且我已经在这个代码片段中进行了几次昏迷.
href.replace(/.*(?=#[^\s]+$)/, '') //strip for ie7
Run Code Online (Sandbox Code Playgroud)
正则表达式是我的盲点,我无法弄清楚其中的大多数.它取代了什么?在#之后是空白吗?
边注.任何人都可以为正则表达式的学费推荐一个好的来源吗?
这是它正在寻找的东西:
.* # any number of characters (optional)
(?= # open a lookahead
# # find a hash tag
[^\s]+ # at least one non-whitespace character
$ # end of line
) # close the lookahead
Run Code Online (Sandbox Code Playgroud)
因此,例如,它匹配散列标记之前的内容:
replace this!#foobar <-- matches: replace this!
hello world#goodbye <-- matches: hello world
no match here ! <-- doesn't match anything because there is no hash
what?# <-- does not match because there is nothing after the hash
what?# asd <-- does not match because there is a whitespace-character
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
114 次 |
| 最近记录: |