这个JavaScript正则表达式是否替换空格

Does this javascript regex replace whitespace?

本文关键字:替换 空格 是否 正则表达式 JavaScript 这个      更新时间:2023-09-26

我正在浏览 Twitter 引导的代码,我已经在这个片段中昏迷了几次。

href.replace(/.*(?=#[^'s]+$)/, '') //strip for ie7

正则表达式是我的盲点,我无法弄清楚其中的大部分。它取代了什么?#后面是空格吗?

旁注。任何人都可以推荐一个好的正则表达式学费来源吗?

以下是它正在寻找的内容:

.*     # 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

因此,例如,它匹配哈希标记之前的内容:

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