oracle匹配靓号的正则表达式_靓号等级生成器,正则+VBA代码

本文介绍了一个使用VBA编写的宏,用于根据预定义的正则表达式匹配Oracle中的靓号,并对其进行等级划分。程序考虑了多种靓号规则,如尾数连号、顺位等,最终将号码等级写入Excel表格。
摘要由CSDN通过智能技术生成

昨天收到一个需求,根据要求生成每个号码的等级(图片)

下面是最后做出的效果

下面是VBA代码

'作者:梁茂业 2019年3月7日

Sub replacePhone1()

'定义起始行

START_ROW = 2

'定义等级

Dim Rng2

Dim level

Dim level_1

Dim level_2

Dim level_3

level_1 = Array(1, 2, 1, 2, 3, 3, 4, 5, 4, 5, 7)

level_2 = Array(0, 1, 1, 2, 3, 1, 2, 3, 3, 4, 5)

level_3 = Array(0, 0, 1, 2, 3, 1, 2, 3, 3, 4, 5)

Set regx = CreateObject("vbscript.regexp")

regx.Global = True

Set Rng = Range("a3:a" & Cells(Rows.Count, 1).End(xlUp).Row)

Rng2 = Sheet2.Range("a2:g" & Sheet2.Cells(Rows.Count, 1).End(xlUp).Row)

For Each rn In Rng

n = n + 1

'基础匹配 是否是手机号

regx.Pattern = "^1\d{10}$"

If regx.Test(rn.Value) Then

'判断号码级别

level = level_3

regx.Pattern = "^(1380772|1380782|1390772|1390782|1980772|1987720|1987722|1987723|1987724|1987725|1987726|1987727|1987728|1987729)"

'第一级

If regx.Test(rn.Value) Then

level = level_1

End If

regx.Pattern = "^(1350772|1360772|1387720|1387721|1387722|1387723|1387724|1387725|1387726|1387727|1387728|1387729|1387820|1387821|1387822|1387823|1387824|1387825|1387826|1387827|1387828|1387829|1397720|1397721|1397722|1397723|1397724|1397725|1397726|1397727|1397728|1397729|1397820|1397821|1397822|1397823|1397824|1397825|1397826|1397827|1397828|1397829|)"

'第二级

If regx.Test(rn.Value) Then

level = level_2

End If

'判断局向

n2 = 0

For i = 1 To UBound(Rng2, 1)

n2 = n2 + 1

n3 = Rng2(n2, 3)

n4 = Rng2(n2, 4)

If rn.Value >= Rng2(n2, 3) And rn.Value <= Rng2(n2, 4) Then

Cells(n + START_ROW, 3) = Rng2(n2, 7)

GoTo area

End If

Next

area:

'尾数顺位9位

regx.Pattern = "(?:0(?=1)|1(?=2)|2(?=3)|3(?=4)|4(?=5)|5(?=6)|6(?=7)|7(?=8)|8(?=9)){8}\d"

If regx.Test(Right(rn.Value, 9)) Then

Cells(n + START_ROW, 4) = "尾数顺位9位"

Cells(n + START_ROW, 2) = "99"

GoTo break

End If

'尾数顺位8位

regx.Pattern = "(?:0(?=1)|1(?=2)|2(?=3)|3(?=4)|4(?=5)|5(?=6)|6(?=7)|7(?=8)|8(?=9)){7}\d"

If regx.Test(Right(rn.Value, 8)) Then

Cells(n + START_ROW, 4) = "尾数顺位8位"

Cells(n + START_ROW, 2) = "99"

GoTo break

End If

'尾数顺位7位

regx.Pattern = "(?:0(?=1)|1(?=2)|2(?=3)|3(?=4)|4(?=5)|5(?=6)|6(?=7)|7(?=8)|8(?=9)){6}\d"

If regx.Test(Right(rn.Value, 7)) Then

Cells(n + START_ROW, 4) = "尾数顺位7位"

Cells(n + START_ROW, 2) = "99"

GoTo break

End If

'尾数连号9位

regx.Pattern = "([\d])\1{8,}"

If regx.Test(Right(rn.Value, 9)) Then

Cells(n + START_ROW, 4) = "尾数连号9位"

Cells(n + START_ROW, 2) = "99"

GoTo break

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值