在Excel中匹配正则expression式的函数?

我有几个单元格在我的表中包含一个ISIN 。

这是一个ISIN的例子: DE0006231004

我创build了一个匹配ISIN的正则expression式: ^[a-zA-Z]{2}[0-9]{10}$

我想在我的单元格上匹配这个正则expression式,如果匹配,则返回1,否则返回0。

这是可能的一个function?

下面的函数将做你所需要的。 如果string不匹配,则返回0(零);如果string匹配,则返回1(一)。

 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 

你可以使用内置的Like方法;

 if "DE0006231009" like "[A-Za-z][A-Za-z]##########" then ...