首页 > 其他 > 详细

ES6中y修饰符合u修饰符

时间:2020-05-03 18:48:44      阅读:56      评论:0      收藏:0      [点我收藏+]

y修饰符:也叫粘连(sticky)修饰符,作用与g修饰符类似,也是全局匹配

g修饰符只要剩余位置中存在匹配就可,而y修饰符确保匹配必须从剩余的第一个位置开始

 

对比:

// g
let a = ‘111  11 1‘

let r1 = /\d+/g
console.log(r1.exec(a))
console.log(r1.exec(a))

Array [ "111" ]
Array [ "11" ]
// y
let a = ‘111  11 1‘

let r2 = /^\d+/y
console.log(r2.exec(a))
console.log(r2.exec(a))

Array [ "111" ]
null

 

u修饰符:含义为“Unicode 模式”,用来正确处理大于\uFFFF的 Unicode 字符。也就是说,会正确处理四个字节的 UTF-16 编码

查看unicode的各种编码 https://www.fileformat.info/info/unicode/char/20bb7/index.htm

ES6中y修饰符合u修饰符

原文:https://www.cnblogs.com/allenzhang-920/p/12822855.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!