无为清净楼资源网 Design By www.qnjia.com

正则表达式的() [] {}有不同的意思。

() 是为了提取匹配的字符串。表达式中有几个()就有几个相应的匹配字符串。

(\s*)表示连续空格的字符串。

[]是定义匹配的字符范围。比如 [a-zA-Z0-9] 表示相应位置的字符要匹配英文字符和数字。[\s*]表示空格或者*号。

{}一般用来表示匹配的长度,比如 \s{3} 表示匹配三个空格,\s[1,3]表示匹配一到三个空格。

(0-9) 匹配 '0-9′ 本身。 [0-9]* 匹配数字(注意后面有 *,可以为空)[0-9]+ 匹配数字(注意后面有 +,不可以为空){1-9} 写法错误。

[0-9]{0,9} 表示长度为 0 到 9 的数字字符串。

// 清除两边的空格   JS中需要自己写正则,JQ中可直接调用$.trim(str)去除字符串前后空格
String.prototype.trim = function() { 
 return this.replace(/(^\s*)|(\s*$)/g, ''); 
}; 
// 合并多个空白为一个空白 
String.prototype.ResetBlank = function() { 
 var regEx = /\s+/g; 
 return this.replace(regEx, ' '); 
}; 
// 保留数字 
String.prototype.GetNum = function() { 
 var regEx = /[^\d]/g; 
 return this.replace(regEx, ''); 
}; 
// 保留中文 
String.prototype.GetCN = function() { 
 var regEx = /[^\u4e00-\u9fa5\uf900-\ufa2d]/g; 
 return this.replace(regEx, ''); 
}; 
// String转化为Number 
String.prototype.ToInt = function() { 
 return isNaN(parseInt(this)) "gi" : "g")), replaceWith); 
 } else { 
  return this.replace(reallyDo, replaceWith); 
 } 
}; 
//格式化字符串 add By 刘景宁 2010-12-09 
String.Format = function() { 
 if (arguments.length == 0) { 
  return ''; 
 } 
 if (arguments.length == 1) { 
  return arguments[0]; 
 } 
 var reg = /{(\d+)"M+": this.getMonth() + 1, //月份   
  "d+": this.getDate(), //日   
  "h+": this.getHours() % 12 == 0 "H+": this.getHours(), //小时   
  "m+": this.getMinutes(), //分   
  "s+": this.getSeconds(), //秒   
  "q+": Math.floor((this.getMonth() + 3) / 3), //季度   
  "S": this.getMilliseconds() //毫秒   
 }; 
 var week = { 
  "0": "\u65e5", 
  "1": "\u4e00", 
  "2": "\u4e8c", 
  "3": "\u4e09", 
  "4": "\u56db", 
  "5": "\u4e94", 
  "6": "\u516d"
 }; 
 if (/(y+)/.test(format)) { 
  format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length)); 
 } 
 if (/(E+)/.test(format)) { 
  format = format.replace(RegExp.$1, ((RegExp.$1.length > 1) "\u661f\u671f" : "\u5468") : "") + week[this.getDay() + ""]); 
 } 
 for (var k in o) { 
  if (new RegExp("(" + k + ")").test(format)) { 
   format = format.replace(RegExp.$1, (RegExp.$1.length == 1) "00" + o[k]).substr(("" + o[k]).length))); 
  } 
 } 
 return format; 
} 
Date.prototype.Diff = function(interval, objDate) { 
 //若参数不足或 objDate 不是日期类型則回传 undefined 
 if (arguments.length < 2 || objDate.constructor != Date) { return undefined; } 
 switch (interval) { 
  //计算秒差               
  case 's': return parseInt((objDate - this) / 1000); 
   //计算分差 
  case 'n': return parseInt((objDate - this) / 60000); 
   //计算時差 
  case 'h': return parseInt((objDate - this) / 3600000); 
   //计算日差 
  case 'd': return parseInt((objDate - this) / 86400000); 
   //计算周差 
  case 'w': return parseInt((objDate - this) / (86400000 * 7)); 
   //计算月差 
  case 'm': return (objDate.getMonth() + 1) + ((objDate.getFullYear() - this.getFullYear()) * 12) - (this.getMonth() + 1); 
   //计算年差 
  case 'y': return objDate.getFullYear() - this.getFullYear(); 
   //输入有误 
  default: return undefined; 
 } 
}; 
//检测是否为空 
Object.prototype.IsNullOrEmpty = function() { 
 var obj = this; 
 var flag = false; 
 if (obj == null || obj == undefined || typeof (obj) == 'undefined' || obj == '') { 
  flag = true; 
 } else if (typeof (obj) == 'string') { 
  obj = obj.trim(); 
  if (obj == '') {//为空 
   flag = true; 
  } else {//不为空 
   obj = obj.toUpperCase(); 
   if (obj == 'NULL' || obj == 'UNDEFINED' || obj == '{}') { 
    flag = true; 
   } 
  } 
 } 
 else { 
  flag = false; 
 } 
 return flag;

以上所述是小编给大家介绍的JS基础教程——正则表达式示例,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!

标签:
js正则表达式

无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com

RTX 5090要首发 性能要翻倍!三星展示GDDR7显存

三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。

首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。

据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。