【Avalon】escape
[\uD800-\uDBFF][\uDC00-\uDFFF]
var rsurrogate = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g
var rnoalphanumeric = /([^\#-~| |!])/g
var escape = function(str) {
//将字符串经过 str 转义得到适合在页面中显示的内容, 例如替换 < 为 <
return String(str).
replace(/&/g, '&').
replace(rsurrogate, function(value) {
console.log('============')
console.log(value)
var hi = value.charCodeAt(0)
var low = value.charCodeAt(1)
return '&#' + (((hi - 0xD800) * 0x400) + (low - 0xDC00) + 0x10000) + ';'
}).
replace(rnoalphanumeric, function(value) {
console.log('------------')
console.log(value)
return '&#' + value.charCodeAt(0) + ';'
}).
replace(/</g, '<').
replace(/>/g, '>')
} str = 'abcdefg123456789[aa]0中过<div>©| !---</div>'
console.log(str)
console.log(escape(str))
// abcdefg123456789[aa]0中过<div>&copy;| !---</div> var r = /([^\#-~| |!])/g // 排除\#-~ 或 空格 或 ! 得到匹配中文
var r1 = /([^\#-~])/g // # -(to) ~ console.log(r.test('12 ji')) //var rr = /[\u4e00-\u9fa5]/g
//console.log(rr.test('12聚宽'))
【Avalon】escape的更多相关文章
- 【CF932F】Escape Through Leaf 启发式合并set维护凸包
[CF932F]Escape Through Leaf 题意:给你一棵n个点的树,每个点有树形ai和bi,如果x是y的祖先,则你可以从x花费$a_x\times b_y$的费用走到y(费用可以为负). ...
- 【BZOJ-1340】Escape逃跑问题 最小割
1340: [Baltic2007]Escape逃跑问题 Time Limit: 5 Sec Memory Limit: 162 MBSubmit: 264 Solved: 121[Submit] ...
- 【Avalon】factory
(function(global, factory) { if (typeof module === "object" && typeof module.expor ...
- 【avalon】data
if (root.dataset) { avalon.fn.data = function (name, val) { name = name && camelize(name) va ...
- 【avalon】offsetParent
offsetParent: function () { var offsetParent = this[0].offsetParent while (offsetParent && a ...
- 【转】escape,encodeURI,encodeURIComponent有什么区别?
在这个页面里面试着搜了一下 「UTF-8」 ,居然没有搜到. escape 和 encodeURI 都属于 Percent-encoding,基本功能都是把 URI 非法字符转化成合法字符,转化后形式 ...
- 【转】escape()、encodeURI()、encodeURIComponent()区别详解
escape().encodeURI().encodeURIComponent()区别详解 原文链接:http://www.cnblogs.com/tylerdonet/p/3483836.html ...
- 【算法】Escape
The students of the HEU are maneuvering for their military training. The red army and the blue army ...
- 【javascript】escape()、encodeURI()、encodeURIComponent()区别详解
JavaScript中有三个可以对字符串编码的函数,分别是: escape,encodeURI,encodeURIComponent,相应3个解码函数:unescape,decodeURI,decod ...
随机推荐
- Oracle “dba_tables”介绍
DBA_TABLES describes all relational tables in the database. Its columns are the same as those in ALL ...
- 批量插入使用SqlBulkCopy
对于大量的数据插入,我们可以使用批量插入功能来提升性能,例如.
- HDU 1754 单点更新,求区间最大值
I Hate It Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- PowerMock遇到的问题——4
当我们在测试一个方法的构造方法的时候,有的时候内部需要new一些对象,这是就需要用到PowerMock.exceptNew(),这个方法,但有时候传的参数有关键字this,比如SAPPublisher ...
- Service相关--读书笔记
2013-12-30 18:16:11 1. Service和Activty都是从Context里面派生出来的,因此都可以直接调用getResource(),getContentResolver()等 ...
- 【STL】-Map/Multimap的用法
初始化: map<string,double> salaries; 算法: 1. 赋值.salaries[ "Pat" ] = 75000.00; 2. 无效的索引将自 ...
- DotNetBar v12.2.0.7 Fully Cracked
PS: 博客园的程序出现问题,导致我的博客不能访问(转到登录页),而我自己由于 Cookies 问题,一直可以访问,所以一直未发现该问题. 感谢冰河之刃告知,thx! 更新信息: http://www ...
- python抓取性感尤物美女图
由于是只用标准库,装了python3运行本代码就能下载到多多的美女图... 写出代码前面部分的时候,我意识到自己的函数设计错了,强忍继续把代码写完. 测试发现速度一般,200K左右的下载速度,也没有很 ...
- 理解Objective C 中id
什么是id,与void *的区别 id在Objective C中是一个类型,一个complier所认可的Objective C类型,跟void *是不一样的,比如一个 id userName, 和vo ...
- 上位机控制led
使用库函数,调试的结果在标红程序上,int main(void){ u8 a; u8 t; u8 len; u16 ti ...