js

来源:互联网 发布:plc触摸屏编程实例 编辑:程序博客网 时间:2024/05/22 16:49

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)


0 0