繁体   English   中英

此javascript正则表达式会替换空白吗?

[英]Does this javascript regex replace whitespace?

我正在浏览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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM