中国.Rick

IT.Man

ASP内容提取(正则表达式应用实例)

电话号码正则表达式(支持手机号码,3-4位区号,7-8位直播号码,1-4位分机号)

((\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$)

匹配格式:
11位手机号码
3-4位区号,7-8位直播号码,1-4位分机号
如:12345678901、1234-12345678-1234

 "^\d+$"  //非负整数(正整数 + 0) 
"^[0-9]*[1-9][0-9]*$"  //正整数 
"^((-\d+)|(0+))$"  //非正整数(负整数 + 0) 
"^-[0-9]*[1-9][0-9]*$"  //负整数 
"^-?\d+$"    //整数 
"^\d+(\.\d+)?$"  //非负浮点数(正浮点数 + 0) 
"^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$"  //正浮点数 
"^((-\d+(\.\d+)?)|(0+(\.0+)?))$"  //非正浮点数(负浮点数 + 0) 
"^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$"  //负浮点数 
"^(-?\d+)(\.\d+)?$"  //浮点数 
"^[A-Za-z]+$"  //由26个英文字母组成的字符串 
"^[A-Z]+$"  //由26个英文字母的大写组成的字符串 
"^[a-z]+$"  //由26个英文字母的小写组成的字符串 
"^[A-Za-z0-9]+$"  //由数字和26个英文字母组成的字符串 
"^\w+$"  //由数字、26个英文字母或者下划线组成的字符串 
"^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$"    //email地址 
"^[a-zA-z]+://(\w+(-\w+)*)(\.(\w+(-\w+)*))*(\?\S*)?$"  //url 
/^13\d{9}$/gi手机号正则表达式
public static bool IsValidMobileNo(string MobileNo)
  {
   const string regPattern = @"^(130|131|132|133|134|135|136|137|138|139)\d{8}$";
   return Regex.IsMatch(MobileNo, regPattern);
  }
正则表达式--验证手机号码:13[0-9]{9}
实现手机号前带86或是+86的情况:^((\+86)|(86))?(13)\d{9}$
电话号码与手机号码同时验证:(^(\d{3,4}-)?\d{7,8})$|(13[0-9]{9}) 
提取信息中的网络链接:(h|H)(r|R)(e|E)(f|F)  *=  *('|")?(\w|\\|\/|\.)+('|"|  *|>)?  
提取信息中的邮件地址:\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*  
提取信息中的图片链接:(s|S)(r|R)(c|C)  *=  *('|")?(\w|\\|\/|\.)+('|"|  *|>)?
提取信息中的IP地址:(\d+)\.(\d+)\.(\d+)\.(\d+)    
提取信息中的中国手机号码:(86)*0*13\d{9}    
提取信息中的中国固定电话号码:(\(\d{3,4}\)|\d{3,4}-|\s)?\d{8}    
提取信息中的中国电话号码(包括移动和固定电话):(\(\d{3,4}\)|\d{3,4}-|\s)?\d{7,14}    
提取信息中的中国邮政编码:[1-9]{1}(\d+){5}    
提取信息中的中国身份证号码:\d{18}|\d{15}    
提取信息中的整数:\d+    
提取信息中的浮点数(即小数):(-?\d*)\.?\d+    
提取信息中的任何数字  :(-?\d*)(\.\d+)?  
提取信息中的中文字符串:[\u4e00-\u9fa5]*    
提取信息中的双字节字符串  (汉字):[^\x00-\xff]*

提取函数:

Function RegExpTest(patrn, strng)
Dim regEx, Match, Matches ' 建立变量。
Set regEx = New RegExp ' 建立正则表达式。
regEx.Pattern = patrn ' 设置模式。
regEx.IgnoreCase = True ' 设置是否区分字符大小写。
regEx.Global = True ' 设置全局可用性。
Set Matches = regEx.Execute(strng) ' 执行搜索。
For Each Match in Matches ' 遍历匹配集合。
RetStr = RetStr & "Match found at position "
RetStr = RetStr & Match.FirstIndex & ". Match Value is '"
RetStr = RetStr & Match.Value & "'." & vbCRLF
Next
RegExpTest = RetStr
End Function

RegExpTest("is.", "IS1 is2 IS3 is4")

« 上一篇 | 下一篇 »
  • 相关文章:

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

日历

最新评论及回复

最近发表

Powered By Z-Blog 1.8 Walle Build 91204 and Theme By BokeZhuti.cn

Copyright RickC.cn [浙ICP备09040539] Some Rights Reserved.