日期:2014-05-16 浏览次数:20374 次
var dateStr = "index?$hh#,$yy#,$gg#"; var regx = /\$(.+)\#/; var d = text.match(regx); for (var i in d) { alert(i+":"+ d[i]); } //上述代码 正则表达式 提取字符串里面 $(.)#这里面的字符串 当字符串里面只有一对字符的时候可以用( var dateStr = "index?$hh#";) 当有多对的时候就出问题......求大神帮忙改一个
var dateStr = "index?$hh#,$yy#,$gg#"; var ar,d=new Array(); var regx = /\$(.+?)\#/g; //var d = dateStr.match(regx); while(ar=regx.exec(dateStr)){ d.push(ar[1]); } for (var i in d) { alert(i+":"+ d[i]); }
------解决方案--------------------
<script type="text/javascript">
var dateStr = "index?$hh#,$yy#,$gg#";
var regx = /\$.+?\#/g;
var d = dateStr.match(regx);
for (var i in d) {
document.write(d[i]+"<br/>")
}
</script>
这样试试