Asp正则表达式提取字符
作者:admin 日期:2012-07-18
正则表达式--验证手机号码: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]*
- 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")
ASP中用正则表达式替换字符找字符
作者:admin 日期:2012-07-18
正则表达式应用非常广泛,特别是在文本处理方面,可以把符合条件的字符替换成别的字符,也可以从文本中找出所有符合条件的字符。
最基本的中英文搜索分词,即把用户输入的搜索关键字分割成中文词和英文词,比如用户输入了: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
广告位