1. 程式人生 > >js正則表示式提取漢字和去掉漢字

js正則表示式提取漢字和去掉漢字

  1. //只提取漢字
  2. function GetChinese(strValue) {  
  3.     if(strValue!= null && strValue!= ""){  
  4.         var reg = /[\u4e00-\u9fa5]/g;   
  5.         return strValue.match(reg).join("");  
  6.     }  
  7.     else
  8.         return"";  
  9. }  
  1.  //去掉漢字
  2. function RemoveChinese(strValue) {  
  3.     if(strValue!= null && strValue
     != 
    ""){  
  4.         var reg = /[\u4e00-\u9fa5]/g;   
  5.        returnstrValue.replace(reg, "");   
  6.     }  
  7.     else
  8.         return"";  
  9. }