Strange regular expression matching problem varcontent @ | @ caocl | @ caoclTEST; contentcontent. replace (|. * gmi,); varreg @ [^ s | @] * $; varstrcontent. match (reg); alert (str); alert (strange content regular expression matching problem
Var content = '@ | @ caocl/ | @ caocl TEST ';
Content = content. replace (/\ |. */gmi ,'');
Var reg =/\ @ [^ \ s | @] * $ /;
Var str = content. match (reg );
Alert (str );
Alert (content );
Alert ('@'. match (reg ));
Remove the content in | and then match
I now matched the content = '@'; but alert (str) is indeed null, alert (content) is '@', alert ('@'. match (reg) is '@';
In this case, str should be '@'. please advise me how to match the correct value. why is this value incorrect?
------ Solution --------------------
Var content = '@ | @ caocl/ | @ caocl TEST ';
@ Isn't there a space behind it?
Change to var reg =/\ @ [^ | @] * $/. this is incorrect.