预览模式: 普通 | 列表

Asp正则表达式提取字符

正则表达式--验证手机号码: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]* 

ASP/Visual Basic代码
  1. Function RegExpTest(patrn, strng)  
  2. Dim regEx, Match, Matches ' 建立变量。  
  3. Set regEx = New RegExp ' 建立正则表达式。  
  4. regEx.Pattern = patrn ' 设置模式。  
  5. regEx.IgnoreCase = True ' 设置是否区分字符大小写。  
  6. regEx.Global = True ' 设置全局可用性。  
  7. Set Matches = regEx.Execute(strng) ' 执行搜索。  
  8. For Each Match in Matches ' 遍历匹配集合。  
  9. RetStr = RetStr & "Match found at position "  
  10. RetStr = RetStr & Match.FirstIndex & ". Match Value is '"  
  11. RetStr = RetStr & Match.Value & "'." & vbCRLF  
  12. Next  
  13. RegExpTest = RetStr  
  14. End Function  
  15.   
  16. RegExpTest("is.""IS1 is2 IS3 is4")  

Tags: asp 正则表达式

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 2179

ASP中用正则表达式替换字符找字符

正则表达式应用非常广泛,特别是在文本处理方面,可以把符合条件的字符替换成别的字符,也可以从文本中找出所有符合条件的字符。

最基本的中英文搜索分词,即把用户输入的搜索关键字分割成中文词和英文词,比如用户输入了:NOKIA诺基亚5700,分割后就是3个词NOKIA、诺基亚、5700,这样更容易找到用户需要的信息。

ASP实现代码举例:

keyword=“NOKIA诺基亚5700” '要分割的关键字
partWord="" ’'保存分割出来的每个关键字
set regEx = new RegExp
regEx.Pattern= "[\w]+" '取出英文,并将全部匹配结果存到数组中去
regEx.IgnoreCase = True ‘忽略大小写
regEx.Global = True '全局匹配
Set Matches=regEx.Execute(keyword)
For Each Matche In Matches '所有匹配结果集
partWord=partWord&Matche&"|" '分词
next
set regEx=nothing
set regEx = new RegExp
regEx.Pattern= "[^\w ]+" '取非(英文+空格),这里W后面有个空格
regEx.IgnoreCase = True
regEx.Global = True
Set Matches=regEx.Execute(keyword)
For Each Matche In Matches
partWord=partWord&Matche&"|"
next

查看更多...

Tags: asp 正则表达式

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 2154

 广告位

↑返回顶部↑