这个正则表达式怎么解? /<tpl\b[^>]*>((?:(?=([^<]+))\2|<(?!tpl\b[^>]*>))*?)<\tpl>/用得是MATCH 方法,返回结果应该包括<tpl></tpl>这对标签吧,但是没包括这对标签的也返回了! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你正则是完全拷贝过来的嘛?怎么连<\/tpl>都被换成<\tpl>了啊 你想要匹配什么啊?匹配:<tpl></tpl>/<tpl\b[^>]*>.+?<\tpl>/ 呵呵你这个正则有问题呀var str = "<tpl>asdfasdfasdfasdf\n<\tpl>";var i = /<tpl\b[^>]*>.+?<\tpl>/g;alert(i.test(str)); 源代码在这里Ext.XTemplate = function(){ Ext.XTemplate.superclass.constructor.apply(this, arguments); var me = this, s = me.html, re = /<tpl\b[^>]*>((?:(?=([^<]+))\2|<(?!tpl\b[^>]*>))*?)<\/tpl>/, nameRe = /^<tpl\b[^>]*?for="(.*?)"/, ifRe = /^<tpl\b[^>]*?if="(.*?)"/, execRe = /^<tpl\b[^>]*?exec="(.*?)"/, m, id = 0, tpls = [], VALUES = 'values', PARENT = 'parent', XINDEX = 'xindex', XCOUNT = 'xcount', RETURN = 'return ', WITHVALUES = 'with(values){ '; s = ['<tpl>', s, '</tpl>'].join(''); while((m = s.match(re))){ var m2 = m[0].match(nameRe), m3 = m[0].match(ifRe), m4 = m[0].match(execRe), exp = null, fn = null, exec = null, name = m2 && m2[1] ? m2[1] : ''; if (m3) { exp = m3 && m3[1] ? m3[1] : null; if(exp){ fn = new Function(VALUES, PARENT, XINDEX, XCOUNT, WITHVALUES + RETURN +(Ext.util.Format.htmlDecode(exp))+'; }'); } } if (m4) { exp = m4 && m4[1] ? m4[1] : null; if(exp){ exec = new Function(VALUES, PARENT, XINDEX, XCOUNT, WITHVALUES +(Ext.util.Format.htmlDecode(exp))+'; }'); } } if(name){ switch(name){ case '.': name = new Function(VALUES, PARENT, WITHVALUES + RETURN + VALUES + '; }'); break; case '..': name = new Function(VALUES, PARENT, WITHVALUES + RETURN + PARENT + '; }'); break; default: name = new Function(VALUES, PARENT, WITHVALUES + RETURN + name + '; }'); } } tpls.push({ id: id, target: name, exec: exec, test: fn, body: m[1]||'' }); s = s.replace(m[0], '{xtpl'+ id + '}'); ++id; } for(var i = tpls.length-1; i >= 0; --i){ me.compileTpl(tpls[i]); } me.master = tpls[tpls.length-1]; me.tpls = tpls;}; 能够把不是tpl的而没有被匹配的发给我看看吗 是我在调试gridpanel时出现的,那段HTML代码不记得了。 while((m = s.match(re)))调试到这里的时候,m的第一个值就是s,第二个值是s中去掉了这对标签<tpl></tpl>中的内容,第三个值是'/tpl>',太奇怪了,不知道是怎么匹配的? 嗯 是这样的m[0]是你匹配的内容m[1]是第一个子模式m[2]是第二个子模式 写的比较乱。滥用环视。<tpl></tpl>之间的很简单var reg = /<tpl>[\s\S]*?<\/tpl>/g; 修改一下。var reg = /<tpl\s[^>]*>[\s\S]*?<\/tpl>/g; js 一段代码分析 jquery 获取FCK 值的问题 dhATV 3.0发布 JavaScrip高手过来帮忙看看! 急救!!!!! 如何实现弹出子窗口时,父窗口不可编辑~ 求网页上编辑视频的技术 请教正则表达式问题 求代码优化??? 表单再进行出错验证时,焦点如何控制??(2)一定给分 帮忙写个js代码 请问有谁能给我讲讲这段代码的具体意思啊
/<tpl\b[^>]*>.+?<\tpl>/
呵呵
你这个正则有问题呀var str = "<tpl>asdfasdfasdfasdf\n<\tpl>";
var i = /<tpl\b[^>]*>.+?<\tpl>/g;
alert(i.test(str));
Ext.XTemplate = function(){
Ext.XTemplate.superclass.constructor.apply(this, arguments); var me = this,
s = me.html,
re = /<tpl\b[^>]*>((?:(?=([^<]+))\2|<(?!tpl\b[^>]*>))*?)<\/tpl>/,
nameRe = /^<tpl\b[^>]*?for="(.*?)"/,
ifRe = /^<tpl\b[^>]*?if="(.*?)"/,
execRe = /^<tpl\b[^>]*?exec="(.*?)"/,
m,
id = 0,
tpls = [],
VALUES = 'values',
PARENT = 'parent',
XINDEX = 'xindex',
XCOUNT = 'xcount',
RETURN = 'return ',
WITHVALUES = 'with(values){ '; s = ['<tpl>', s, '</tpl>'].join(''); while((m = s.match(re))){
var m2 = m[0].match(nameRe),
m3 = m[0].match(ifRe),
m4 = m[0].match(execRe),
exp = null,
fn = null,
exec = null,
name = m2 && m2[1] ? m2[1] : ''; if (m3) {
exp = m3 && m3[1] ? m3[1] : null;
if(exp){
fn = new Function(VALUES, PARENT, XINDEX, XCOUNT, WITHVALUES + RETURN +(Ext.util.Format.htmlDecode(exp))+'; }');
}
}
if (m4) {
exp = m4 && m4[1] ? m4[1] : null;
if(exp){
exec = new Function(VALUES, PARENT, XINDEX, XCOUNT, WITHVALUES +(Ext.util.Format.htmlDecode(exp))+'; }');
}
}
if(name){
switch(name){
case '.': name = new Function(VALUES, PARENT, WITHVALUES + RETURN + VALUES + '; }'); break;
case '..': name = new Function(VALUES, PARENT, WITHVALUES + RETURN + PARENT + '; }'); break;
default: name = new Function(VALUES, PARENT, WITHVALUES + RETURN + name + '; }');
}
}
tpls.push({
id: id,
target: name,
exec: exec,
test: fn,
body: m[1]||''
});
s = s.replace(m[0], '{xtpl'+ id + '}');
++id;
}
for(var i = tpls.length-1; i >= 0; --i){
me.compileTpl(tpls[i]);
}
me.master = tpls[tpls.length-1];
me.tpls = tpls;
};
m[0]是你匹配的内容
m[1]是第一个子模式
m[2]是第二个子模式
<tpl></tpl>之间的很简单var reg = /<tpl>[\s\S]*?<\/tpl>/g;
var reg = /<tpl\s[^>]*>[\s\S]*?<\/tpl>/g;