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

正则匹配的奇怪有关问题

WBOY
Release: 2016-06-13 13:10:24
Original
896 people have browsed it

正则匹配的奇怪问题
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)是‘@’,alert('@'.match(reg))是‘@’;
这样str应该也是‘@’才对,求大神指教怎么匹配出正确的值,这样的值又为什么不对

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template