您的位置:首页 > Web前端 > JavaScript

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)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: