日期:2014-05-16  浏览次数:20493 次

正则表达匹配
经过两次的Js encodeURIComponent 处理过的汉字 如下

%25E6%2597%25A5%25E6%259C%25AC

%25E6%2597%25A5%25E6%259C%25AC%25E6%2598%25AF%25E4%25BB%2580%25E4%25B9%2588%25E4%25B8%259C%25E8%25A5%25BF

现在有没有一个正则匹配这样经过编码后的 表达式 

------解决方案--------------------

str="%25E6%2597%25A5%25E6%259C%25AC";
reg=/%[\da-z]{4}/ig;
alert( reg.test(str) )

------解决方案--------------------
var a="%25E6%2597%25A5%25E6%259C%25AC%25E6%2598%25AF%25E4%25BB%2580%25E4%25B9%2588%25E4%25B8%259C%25E8%25A5%25BF";
var reg=/^(%[\da-fA-F]{4})+$/;
alert(reg.test(a));
------解决方案--------------------

var str1 = '%25E6%2597%25A5%25E6%259C%25AC' , 
str2 = '%25E6%2597%25A5%25E6%259C%25AC%25E6%2598%25AF%25E4%25BB%2580%25E4%25B9%2588%25E4%25B8%259C%25E8%25A5%25BF';
var reg = new RegExp(str1);
console.log(reg.test(str2));
console.log(str2.match(reg));

你看下上面是不是你要的效果,其实不是很明白LZ的意思
------解决方案--------------------

var str1 = '%25E6%2597%25A5%25E6%259C%25AC' , 
str2 = '%25E6%2597%25A5%25E6%259C%25AC%25E6%2598%25AF%25E4%25BB%2580%25E4%25B9%2588%25E4%25B8%259C%25E8%25A5%25BF';
console.log(str1.match(/%([\d\w]*)/g));
console.log(str2.match(/%([\d\w]*)/g));