练习正则表达式

1.regexp
var str = 'dftd5rw5e1231211yasgdafdt12wq12fw1ft';
var pattern = /[daf]/ig;
var pattern = /[daf]{2}/ig;
//
var pattern = /[^daf]/ig;
//
var pattern = /^[a-z].*\d$/g;
var str = 'a29';
var pattern = /^\d{11}$/;
//手机号

var pattern = /^([a-z]|[0-9]){3,12}@([a-z]|[0-9]){2,10}\.[a-z]{3,5}$/ig;
var str = '[email protected]';
//匹配邮箱
console.log(str.match(pattern));


var str = 'ababa';
var pattern = /([a-z]){2}.\1/g;
console.log(str.match(pattern));
//abab
//如果匹配上直接抛出,没有匹配上从下一个继续开始  
	
2.包装器
//Boolean Number String
var n = new Number(123);
console.log(n);//[number:123]
console.log(typeof n);//object
console.log(n instanceof Number);//true
console.log(n instanceof Object);//true
var m = 123;
console.log(m);//123
console.log(typeof m);//number
console.log(m instanceof Number);//false
console.log(m instanceof Object);//false

var o = new Object(123);
console.log(o);//[number:123]
console.log(o instanceof Number);//true
console.log(o instanceof Object);//true
//基本类型到包装器类型转换 new

3.String
//length 字符串长度/个数
//charAt(index)获取index 位置上的字符
//charCodeAt(index) index ASCII 
var str = ' ys a uc a cy c';
str.split('').forEach(function(item){
	console.log(item);
});
for(i=0;i

你可能感兴趣的:(JS)