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

正则匹配的奇怪有关问题

WBOY
Release: 2016-06-13 10:52:52
Original
935 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)[email protected],alert('@'.match(reg))[email protected];
[email protected],求大神指教怎么匹配出正确的值,这样的值又为什么不对

------解决方案--------------------
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