惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - Maxer`s Blog

用C#生成随机中文汉字验证码(转) 序列化与反序列化 - Maxer`s Blog - 博客园 大家救命啊:系统表更新导致数据库崩溃,有没有办法还原? //以解决,谢谢大家关注 一些我收集的常用正则表达式 - Maxer`s Blog SQLServer和Access、Excel数据传输简单总结 动态SQL语句 转-javascript 问题集合 - Maxer`s Blog 使用Session常见问题集锦 - Maxer`s Blog TreeView控件问题汇总 ASP.NET 2.0学习笔记之$ - Maxer`s Blog ASP.NET 2.0学习笔记之Object Tag Syntax - Maxer`s Blog ASP.NET 2.0学习笔记之Code Directory 网站恢复正常了,感谢Howej ! 推荐一个好用的PDF转TXT软件 测试从dasblog发文章到博客园 [导入]注册了StartNow.CN域名 - Maxer`s Blog [导入]新年钟声响了,现在是2006了 [导入]今天去签了新电信息科技 [导入]应届毕业生该怎样准备你的未来 - Maxer`s Blog
JS常用正则表达式
Maxer`s Blog · 2006-08-09 · via 博客园 - Maxer`s Blog

匹配中文字符的正则表达式: [\u4e00-\u9fa5]
匹配双字节字符(包括汉字在内):[^\x00-\xff]
匹配空行的正则表达式:\n[\s| ]*\r
匹配HTML标记的正则表达式:/<(.*)>.*<\/\1>|<(.*) \/>/ 
匹配首尾空格的正则表达式:(^\s*)|(\s*$)
匹配Email地址的正则表达式:\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
匹配网址URL的正则表达式:http://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?

(1)应用:计算字符串的长度(一个双字节字符长度计2,ASCII字符计1)         
    String.prototype.len=function(){return this.replace([^\x00-\xff]/g,"aa").length;}

(2)应用:javascript中没有像vbscript那样的trim函数,我们就可以利用这个表达式来实现
   String.prototype.trim = function()
   {
      return this.replace(/(^\s*)|(\s*$)/g, "");
   }
(3)应用:利用正则表达式分解和转换IP地址
   function IP2V(ip) //IP地址转换成对应数值
   {
      re=/(\d+)\.(\d+)\.(\d+)\.(\d+)/g //匹配IP地址的正则表达式
      if(re.test(ip))
      {
         return RegExp.$1*Math.pow(255,3))+RegExp.$2*Math.pow(255,2))+RegExp.$3*255+RegExp.$4*1
      }
      else
      {
         throw new Error("Not a valid IP address!")
      }
   }
(4)应用:从URL地址中提取文件名的javascript程序
   s="http://www.9499.net/page1.htm";
   s=s.replace(/(.*\/){0,}([^\.]+).*/ig,"$2") ; //Page1.htm
(5)应用:利用正则表达式限制网页表单里的文本框输入内容
    用正则表达式限制只能输入中文:onkeyup="value=value.replace(/[^\u4E00-\u9FA5]/g,'') " onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\u4E00-\u9FA5]/g,''))"
    用正则表达式限制只能输入全角字符: onkeyup="value=value.replace(/[^\uFF00-\uFFFF]/g,'') " onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\uFF00-\uFFFF]/g,''))"
    用正则表达式限制只能输入数字:onkeyup="value=value.replace(/[^\d]/g,'') "onbeforepaste= "clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"
    用正则表达式限制只能输入数字和英文:onkeyup="value=value.replace(/[\W]/g,'')  "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"

posted on 2006-08-09 13:10  Maxer`s Blog  阅读(586)  评论()    收藏  举报