【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 ...
随机推荐
- 在 Visual C# 项目中调用 VBA 中的代码
https://msdn.microsoft.com/zh-cn/library/Bb608613.aspx http://www.cnblogs.com/yangbin1005/archive/20 ...
- Web API初印象
理解REST,RESTful和Web API 1.REST:Representational State Transfer表征状态转移,是Roy Fielding博士在2000年他的博士论文中提出来的 ...
- 利用百度地图开源sdk获取地址信息。
注册百度开发者帐号,下载相关sdk 添加权限: 添加百度注册访问应用(AK)码 添加源代码文件到libs文件: 代码如下: package com.lixu.baidu_gps; import com ...
- Ubuntu 14.04下安装eclipse搭建C++开发环境
安装过程分为两部分:1.JAVA开发环境,即JDK的安装:2.eclipse的安装: 一.安装包下载 1.JDK官网下载地址:http://www.oracle.com/technetwork/jav ...
- not use jquery
document.getElementById('myElement');document.querySelector('#myElement'); document.getElementsByCla ...
- 2799元的HTC One时尚版要卖疯了
俗话说“好人有好报”,这句话同样可以应用到手机上.本月初,HTC正式公布了HTC One时尚版的售价,裸机2799元,礼包价2999元(配智能立显保护套).该价格一出,立刻引来一片哗然.因为大家都不相 ...
- load get selectone 或者selectlist 以及hql查询语句不用提交事务
提交事务是么有必要的 而且有时候subselect batchsize 会失效
- python文件打包格式,pip包管理
1..whl是python文件的一种打包格式, 在有些情况下,可以将文件的后缀名改为.zip并解压 2.cmd中,提示pip版本太低,先升级pip pip install --upgrade pi ...
- MVC的传递数据的方法
1.使用ViewBag #region 0.2 Action方法 + ActionResult Index2() /// <summary> /// Action方法 /// </s ...
- ZOJ 3747 - Attack on Titans (递推)
题意:有三个兵种R,G,C,选取N个排成一列,要求G至少有M个连续的,R至多有K个连续的,问有多少种排列方式. 此题与UVa 10328 - Coin Toss非常相似,都是问某个字符连续出现的种数. ...