⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 常用正则表达式.htm

📁 java的正则表达式的详细说明
💻 HTM
📖 第 1 页 / 共 2 页
字号:
      's/\(....\)\(..\)\(..\)/\1 \2 \3/'|read year month day&nbsp;&nbsp;<BR>echo 
      $year $month $day [/code] <BR><BR>[b]文件内容倒序输出[/b] <BR>[code]sed 
      '1!G;h;$!d'&nbsp;&nbsp;oldfile 
&gt;newfile[/code]</TD></TR></TBODY></TABLE><BR></TD /></TR /><TR></TR><TD 
class=smalltxt bgcolor="#fff9ff"></TD>[code]匹配中文字符的正则表达式: 
<BR>[\u4e00-\u9fa5]<BR><BR>匹配双字节字符(包括汉字在内):<BR>[^\x00-\xff]<BR><BR>匹配空行的正则表达式:<BR>\n[\s| 
]*\r<BR><BR>匹配HTML标记的正则表达式:<BR>/&lt;(.*)&gt;.*&lt;\/\1&gt;|&lt;(.*) \/&gt;/ 
<BR><BR>匹配首尾空格的正则表达式:<BR>(^\s*)|(\s*$) 
<BR><BR>URL:<BR>[url]http://([/url][\w-]+\.)+[\w-]+(/[\w- 
./?%&amp;=]*)?<BR><BR>Email:<BR>\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*<BR><BR>中华人民共和国电话号码<BR>(\(\d{3}\)|\d{3}-)?\d{8}<BR><BR>中华人民共和国邮编<BR>\d{6}<BR><BR>门丁注册的id格式:2-12位,数字、字符、下划线(0-9,a-z,A-Z,_) 
<BR>^[0-9a-zA-Z]+(\w){1,11}[/code]</TD /></TR /></TBODY /></TABLE /><BR>
<TABLE class=tableborder cellSpacing=0 cellPadding=4 width="98%" align=center>
  <TBODY>
  <TR>
    <TD bgColor=#f8f1e5></TD></TR>
  <TR>
    <TD class=smalltxt bgColor=#fff9ff>[color=red]蓝吧甜 
      宝宝:[/color][color=blue]主人,陪我去森林里玩好不好?<BR>你和宝宝在森林里找了个好东西给你~~管理员作的特别科研卡!<BR>卡片说明:获得社区特别科研基金100个金币。<BR>卡片效果:得到100金币。<BR>你高兴我也高兴![/color]<BR>[img]http://www.xmsq.com/web/images/card/23.jpg[/img]<BR><BR>[code]匹配中文字符的正则表达式: 
      [\u4e00-\u9fa5]<BR><BR>匹配双字节字符(包括汉字在内):[^\x00-\xff]<BR><BR>匹配空行的正则表达式:\n[\s| 
      ]*\r<BR><BR>匹配HTML标记的正则表达式:/&lt;(.*)&gt;.*&lt;\/\1&gt;|&lt;(.*) \/&gt;/ 
      <BR><BR>匹配首尾空格的正则表达式:(^\s*)|(\s*$)(像vbscript那样的trim函数)<BR><BR>匹配Email地址的正则表达式:\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*<BR><BR>匹配网址URL的正则表达式:[url]http://([/url][\w-]+\.)+[\w-]+(/[\w- 
      ./?%&amp;=]*)?<BR>---------------------------------------------------------------------------<BR>以下是例子:<BR><BR>利用正则表达式限制网页表单里的文本框输入内容:<BR><BR>用正则表达式限制只能输入中文:onkeyup="value=value.replace(/[^\u4E00-\u9FA5]/g,'')" 
      onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\u4E00-\u9FA5]/g,''))"<BR><BR>1.用正则表达式限制只能输入全角字符: 
      onkeyup="value=value.replace(/[^\uFF00-\uFFFF]/g,'')" 
      onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\uFF00-\uFFFF]/g,''))"<BR><BR>2.用正则表达式限制只能输入数字:onkeyup="value=value.replace(/[^\d]/g,'') 
      "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"<BR><BR>3.用正则表达式限制只能输入数字和英文:onkeyup="value=value.replace(/[\W]/g,'') 
      "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"<BR><BR>4.计算字符串的长度(一个双字节字符长度计2,ASCII字符计1)<BR><BR>String.prototype.len=function(){return 
      this.replace([^\x00-\xff]/g,"aa").length;}<BR><BR>5.javascript中没有像vbscript那样的trim函数,我们就可以利用这个表达式来实现,如下:<BR><BR>String.prototype.trim 
      = function()<BR>{<BR>&nbsp; &nbsp; return this.replace(/(^\s*)|(\s*$)/g, 
      "");<BR>}<BR><BR>利用正则表达式分解和转换IP地址:<BR><BR>6.下面是利用正则表达式匹配IP地址,并将IP地址转换成对应数值的Javascript程序:<BR><BR>function 
      IP2V(ip)<BR>{<BR>re=/(\d+)\.(\d+)\.(\d+)\.(\d+)/g&nbsp;&nbsp;//匹配IP地址的正则表达式<BR>if(re.test(ip))<BR>{<BR>return 
      RegExp.$1*Math.pow(255,3))+RegExp.$2*Math.pow(255,2))+RegExp.$3*255+RegExp.$4*1<BR>}<BR>else<BR>{<BR>throw 
      new 
      Error("不是一个正确的IP地址!")<BR>}<BR>}<BR><BR>不过上面的程序如果不用正则表达式,而直接用split函数来分解可能更简单,程序如下:<BR><BR>var 
      ip="10.100.20.168"<BR>ip=ip.split(".")<BR>alert("IP值是:"+(ip[0]*255*255*255+ip[1]*255*255+ip[2]*255+ip[3]*1))[/code]</TD></TR></TBODY></TABLE></P></DIV></DIV>
<P></P>
<P class=diaryFoot>【作者: <A 
onclick="window.open('http://publishblog.blogchina.com/blog/postMessage.b?receiver=148673','发送短消息','width=520, height=455')" 
href="javascript:void(0);">冯唐</A>】【访问统计:
<SCRIPT language=JavaScript src="常用正则表达式.files/PageServlet"></SCRIPT>
】【2006年01月4日 星期三 10:42】【 <A 
href="javascript:void(keyit=window.open('http://blogmark.blogchina.com/jsp/key/quickaddkey.jsp?k='+encodeURI('常用正则表达式 ')+'&amp;u='+encodeURI('http://vondon.blogchina.com/vondon/4094789.html')+'&amp;c='+encodeURI(''),'keyit','scrollbars=no,width=500,height=430,status=no,resizable=yes'));keyit.focus();">加入博采</A>】【<A 
href="javascript:window.print();">打印</A>】 </TD></P></DIV>
<DIV class=operation><A name=trackback>
<H3>Trackback</H3></A>
<P class=trackback>你可以使用这个链接引用该篇文章 
http://publishblog.blogchina.com/blog/tb.b?diaryID=4094789 </P></DIV>
<DIV class=operation><A name=relatedDiary>
<H3>博客手拉手</H3></A>
<TABLE>
  <TBODY>
  <TR>
    <TD align=left><A title=正则表达式之道[转] 
      href="http://purpleendurer.blogchina.com/3797229.html" 
      target=_blank>正则表达式之道[转]</A></TD>
    <TD align=right><A title=http://purpleendurer.blogchina.com/ 
      href="http://purpleendurer.blogchina.com/" target=_blank>紫郢剑侠㊣</A></TD></TR>
  <TR>
    <TD align=left><A title="经典正则表达式(ZT) by lemon" 
      href="http://ishyboy.blogchina.com/4010588.html" target=_blank>经典正则表达式(ZT) 
      by lemon</A></TD>
    <TD align=right><A title=http://ishyboy.blogchina.com/ 
      href="http://ishyboy.blogchina.com/" target=_blank>ishyboy</A></TD></TR>
  <TR>
    <TD align=left><A title=正则表达式使用详解[转] 
      href="http://purpleendurer.blogchina.com/3797269.html" 
      target=_blank>正则表达式使用详解[转]</A></TD>
    <TD align=right><A title=http://purpleendurer.blogchina.com/ 
      href="http://purpleendurer.blogchina.com/" target=_blank>紫郢剑侠㊣</A></TD></TR>
  <TR>
    <TD align=left><A title=常用正则表达式 
      href="http://purpleendurer.blogchina.com/3797305.html" 
      target=_blank>常用正则表达式</A></TD>
    <TD align=right><A title=http://purpleendurer.blogchina.com/ 
      href="http://purpleendurer.blogchina.com/" target=_blank>紫郢剑侠㊣</A></TD></TR>
  <TR>
    <TD align=left><A title=正则表达式使用详解 
      href="http://wudale.blogchina.com/3806153.html" 
    target=_blank>正则表达式使用详解</A></TD>
    <TD align=right><A title=http://wudale.blogchina.com/ 
      href="http://wudale.blogchina.com/" target=_blank>wudale</A></TD></TR>
  <TR>
    <TD align=left><A title=正则表达式之正负向预查 
      href="http://purpleendurer.blogchina.com/3797384.html" 
      target=_blank>正则表达式之正负向预查</A></TD>
    <TD align=right><A title=http://purpleendurer.blogchina.com/ 
      href="http://purpleendurer.blogchina.com/" target=_blank>紫郢剑侠㊣</A></TD></TR>
  <TR>
    <TD align=left><A title=Java中使用c实现字符串匹配 
      href="http://wcjok.blogchina.com/3786326.html" 
      target=_blank>Java中使用c实现字符串匹配</A></TD>
    <TD align=right><A title=http://wcjok.blogchina.com/ 
      href="http://wcjok.blogchina.com/" target=_blank>茫茫</A></TD></TR>
  <TR>
    <TD align=left><A title=在ASP中用“正则表达式对象”来校验数据的合法性 
      href="http://ilvs.blogchina.com/3823288.html" 
      target=_blank>在ASP中用“正则表达式对象”来校验数据的合法性</A></TD>
    <TD align=right><A title=http://ilvs.blogchina.com/ 
      href="http://ilvs.blogchina.com/" target=_blank>天使ηò哭</A></TD></TR>
  <TR>
    <TD align=left><A title=文件搜索器refrain 
      href="http://hzgmaxwell.blogchina.com/3776867.html" 
      target=_blank>文件搜索器refrain</A></TD>
    <TD align=right><A title=http://hzgmaxwell.blogchina.com/ 
      href="http://hzgmaxwell.blogchina.com/" target=_blank>hzgmaxwell</A></TD></TR>
  <TR>
    <TD align=left><A title=.学会表达 
      href="http://xuyunzou.blogchina.com/3794903.html" 
    target=_blank>.学会表达</A></TD>
    <TD align=right><A title=http://xuyunzou.blogchina.com/ 
      href="http://xuyunzou.blogchina.com/" 
  target=_blank>xuyunzou</A></TD></TR></TBODY></TABLE></DIV>
<DIV class=operation><A name=comment>
<H3>回复</H3></A>
<TABLE cellSpacing=0 cellPadding=0 width=700 border=0>
  <TBODY></TBODY></TABLE></DIV>
<DIV class=operation>
<TABLE class=comment cellSpacing=0 cellPadding=0 width=700 border=0>
  <FORM id=replyForm method=post><INPUT type=hidden value=146595 name=blogID> 
  <INPUT type=hidden value=4094789 name=diaryID> <INPUT type=hidden value=vondon 
  name=blogDomino>
  <SCRIPT>
if(getCookie('userID') == null){        
document.write('<tr><td width="70">发布人:</td>');
document.write('<td width="150"> <input name="remark.authorNameFUI" type="text" size="20" class="inputStyle" maxlength="20"></td>');
document.write('<td width="70">邮箱:</td>');
document.write('<td width="435"> <input name="remark.authorEmail" type="text" size="20" class="inputStyle" maxlength="40"></td>');
document.write('</tr><tr><td>主 页:</td>');
document.write('<td colspan="3"> <input name="remark.authorURL" type="text" class="inputStyle" value="HTTP://" size="63" maxlength="100"></td></tr>');
}else{
document.write('<input type="hidden" name="remark.authorNameFUI" value="Blogchina网友">');
}
</SCRIPT>
   
  <TBODY>
  <TR>
    <TD width=70>验证码:</TD>
    <TD><INPUT class=inputStyle maxLength=4 name=validateCode></TD>
    <TD>&nbsp;&nbsp;<IMG src="常用正则表达式.files/getValidateImg.gif" 
border=0></TD></TR>
  <TR align=left>
    <TD colSpan=4>评论内容:<BR><TEXTAREA class=textStyle id=remark name=remark.remarkFUI rows=8 cols=60>          </TEXTAREA> 
    </TD></TR>
  <TR align=left>
    <TD colSpan=4>              <INPUT onclick=reply() type=button value=提交>   
<INPUT type=reset value=重置> </TD></TR></FORM></TBODY></TABLE></DIV></DIV>
<SCRIPT src="常用正则表达式.files/extend3.js" type=text/javascript></SCRIPT>

<DIV id=footer><A href="http://blog.bokee.com/">2003-2004 BOKEE.COM All rights 
reserved</A><BR><A href="http://www.blogdriver.com/">Powered by BlogDriver 
2.1</A> </DIV></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -