这个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
相关文章:
- 我如何找到一个句子中的所有空格并替换忽略它们
- 用空格替换下划线PHP
- 用空格替换+
- 如何替换JavaScript字符串中除字母和数字之外的所有内容(空格/符号)
- 用空格替换单引号和其他符号
- Ajax 用 + 替换空格
- 字符串替换正则表达式,开头为空格
- 如何用空格替换下划线
- 根据javascript中的逗号索引替换空格
- JavaScript:在 XMLSerializer 错误地解析实体后,用 html 160 实体替换三个空格
- 使用简单的角度滤波器来替换输入字符串中某些字符串的所有出现,而不考虑大小写和空格
- 在搜索表单中,替换空格或仅使用正则表达式的隐词和数字
- 在javascript中用正则表达式替换空格
- Javascript 如果字符串包含空格,则用破折号替换空格
- 用正则表达式替换空格,而不替换空的 HTML 标记
- 这个JavaScript正则表达式是否替换空格
- 替换空格javascript
- 替换空格,但不替换括号之间的空格
- 内容替换功能:用下划线替换空格
- 用随机值替换空格