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

JS正则格式化日期,在字符串中插入内容
var getBirthdayFromIdCard = function(idCard){
	var birthday = "";
	if(idCard != null && idCard != ""){
		if(idCard.length == 15){
			birthday = "19"+idCard.substr(6,6);
		} else if(idCard.length == 18){
			birthday = idCard.substr(6,8);
		}
		
		birthday = birthday.replace(/(.{4})(.{2})/,"$1-$2-");
	}
	return birthday;
}

alert(getBirthdayFromIdCard("130503670401001"));
// 1967-04-01

alert(getBirthdayFromIdCard("420621188905021111"));
// 1989-05-02

?

?

var str = 'abcdefg';
str = str.replace(/(.{3})/,"$1BBB");
alert(str);//abcBBBdefg

?