excel中用正则匹配,Excel中正则表达式的匹配功能?

本文介绍了一个用于验证ISIN(国际证券标识符)的VBScript正则表达式函数。该函数能够判断给定字符串是否符合ISIN的标准格式,并返回相应的匹配结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

I have several cells in my sheet which contain an ISIN.

Here is an example of an ISIN: DE0006231004

I have created a regular expression which matches the ISIN:

^[a-zA-Z]{2}[0-9]{10}$

I want to match this regex on my cell and give a 1 if it matches otherwise a 0.

Is this possible with a function?

解决方案

The following function will do what you need. It will return either 0 (zero) if string doesn't match or 1 (one) if the string matches to pattern.

Function MatchISIN(ISIN As String)

Dim regEx As Object

Set regEx = CreateObject("vbscript.regexp")

regEx.Pattern = "^[a-zA-Z]{2}[0-9]{10}$"

regEx.IgnoreCase = True

regEx.Global = True

Dim Matches As Object

Set Matches = regEx.Execute(ISIN)

MatchISIN = Matches.Count

End Function

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值