Home >Backend Development >PHP Tutorial >正则匹配的奇怪有关问题

正则匹配的奇怪有关问题

WBOY
WBOYOriginal
2016-06-13 10:52:52943browse

正则匹配的奇怪问题
var content = '@ || @caocl /抱拳|| @caocl TEST';
content = content.replace(/\|\|.*/gmi, '');
var reg = /\@[^\s|@]*$/ ;
var str = content.match(reg);
alert(str);
alert(content);
alert('@'.match(reg));

将content里||后的内容去掉然后匹配

我现在匹配出了content = '@';但是alert(str)确实null,alert(content)[email protected],alert('@'.match(reg))[email protected];
[email protected],求大神指教怎么匹配出正确的值,这样的值又为什么不对

------解决方案--------------------
var content = '@ || @caocl /抱拳|| @caocl TEST';
@ 后面不是哟个空格吗
改成 var reg = /\@[^|@]*$/ ; 这样不就对了

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn