js
2015-12-08 17:25
639 查看
1.js正则表达式多个匹配项,通过这种方式最方便。
var text = "hello1-hello2-hello3";
var regG = /(he(ll)o\d)\-?/g;
// skip hello1
regG.lastIndex = 5;
var globalResult = null;
while ((globalResult = regG.exec(text)) != null) {
console.log("=============")
console.log(globalResult[0]); //支持分组
console.log(globalResult[1]);
console.log(globalResult[2]);
//每一次lastIndex都会变化
console.log("last index is " + globalResult["index"]);
}
/abc/g.source => abc,
/abc/g.flags => g //ecmascript 6
2.对于非BMP(Basic multiligual plane)的字符,可以使用如下方法
"\u12345".codePointAt(0)获得其code point,该值大与0xFFFF,
String.fromCodePoint(104371)
var text = "hello1-hello2-hello3";
var regG = /(he(ll)o\d)\-?/g;
// skip hello1
regG.lastIndex = 5;
var globalResult = null;
while ((globalResult = regG.exec(text)) != null) {
console.log("=============")
console.log(globalResult[0]); //支持分组
console.log(globalResult[1]);
console.log(globalResult[2]);
//每一次lastIndex都会变化
console.log("last index is " + globalResult["index"]);
}
/abc/g.source => abc,
/abc/g.flags => g //ecmascript 6
2.对于非BMP(Basic multiligual plane)的字符,可以使用如下方法
"\u12345".codePointAt(0)获得其code point,该值大与0xFFFF,
String.fromCodePoint(104371)
相关文章推荐
- JS横向延时2级下拉菜单
- html中js通过指定的年月获取该月的天数
- 跨域访问的两种解决方式:jsonp和cors
- 跨域访问的两种解决方式:jsonp和cors
- javascript中对cookie的存取查操作
- html页面中js获取当前url下指定参数的值
- js实现自定义事件(字面量 && 原型)
- JavaScript停止冒泡和阻止浏览器默认行为
- JavaScript学习之窗口
- js效果
- angular表格带筛选分页,本地json
- js浅copy和深copy
- js BigDecimal
- javascript(substr与substring)
- JS中使用EL表达式
- javascript-逻辑与(&&)逻辑或(||)
- JS代码读取
- JavaScript学习(5.5.6):跳转之try/catch/finally语句
- JavaScript学习(5.5.5):跳转之throw语句
- JS window对象常用方法