本文目录一览:

EXCEL 匹配正则表达式

可以用vba完成,按住alt依次按f11,i,m

粘贴代码后按f5即可在c列得到结果

Sub Test()

atr = Range("a65536").End(xlUp).Row

btr = Range("b65536").End(xlUp).Row

a = Range("a1:a" atr).Value

b = Range("b1:b" btr).Value

ReDim c(1 To atr, 1 To 1)

Set reg = CreateObject("vbscript.regexp")

With reg

.Global = True

.IgnoreCase = True

For ar = 1 To atr

For br = 1 To btr

.Pattern = b(br, 1)

If .Test(a(ar, 1)) Then

c(ar, 1) = "匹配"

Exit For

End If

Next

Next

End With

Range("c1:c" atr) = c

Set reg = Nothing

End Sub

Excel 如何怎么编写正则表达式

Function test(rng As Range) As String

Dim reg

'创建正则表达式对像

Set reg = CreateObject("vbscript.regexp")

'设置匹配文本

reg.Pattern = "/d+"

reg.Global = True

'替代模式

'result = reg.Replace(rng.Text, "")

'查找模式

Set m = reg.Execute(rng.Text)

test = m.Item(0).Value

End Function

正则表达式怎么在EXCEL使用

工具/材料:Microsoft Office Excel2016版,Excel表格。

1、首先选中Excel表格,双击打开。

2、然后在该界面中,选中要使用正则表达式的单元格。

3、再者在该界面中,公式栏中输入正则表达式的公式“=RegexString(A1,"([/d]+)",1)”。

4、其次在该界面中,单元格里显示正则表达式结果。

5、继续在该界面中,选中单元格,向下拖动。

6、最后在该界面中,成功显示正则表达式结果。

excel中使用正则表达式

Function JiSuan(Rng As Range) As Single

    Dim Reg As New RegExp

    Dim R As String

    On Error GoTo ErrHand

    R = (Rng)

    Reg.Global = True

    Reg.Pattern = "[/u4e00-/u9fa5]|m|M"

    R = Reg.Replace(R, "")

    Reg.Pattern = "×"

    R = Reg.Replace(R, "*")

    RegSZCC R

    RegSZJJ R

    JiSuan = Round(CSng(R), 4)

    Set Reg = Nothing

    Exit Function

ErrHand:

    JiSuan = Err.Description

End Function

Sub RegSZCC(ByRef S As String)

    Dim Reg As New RegExp

    Dim MS

    Dim R As String

    Reg.Pattern = "(/d+/.{0,1}/d*)(/*|//)(/d+/.{0,1}/d*)"

    Set MS = Reg.Execute(S)

    If MS.Count = 1 Then

        If MS(0).SubMatches(1) = "/" Then

            R = Format(CSng(MS(0).SubMatches(0)) / CSng(MS(0).SubMatches(2)), "0.00000")

        Else

            R = Format(CSng(MS(0).SubMatches(0)) * CSng(MS(0).SubMatches(2)), "0.00000")

        End If

        S = Reg.Replace(S, R)

        RegSZCC S

    End If

End Sub

Sub RegSZJJ(ByRef S As String)

    Dim Reg As New RegExp

    Dim MS

    Dim R As String

    Reg.Pattern = "(/d+/.{0,1}/d*)(/+|/-)(/d+/.{0,1}/d*)"

    Set MS = Reg.Execute(S)

    If MS.Count = 1 Then

        If MS(0).SubMatches(1) = "+" Then

            R = Format(CSng(MS(0).SubMatches(0)) + CSng(MS(0).SubMatches(2)), "0.00000")

        Else

            R = Format(CSng(MS(0).SubMatches(0)) - CSng(MS(0).SubMatches(2)), "0.00000")

        End If

        S = Reg.Replace(S, R)

        RegSZJJ S

    End If

End Sub

EXCEL中调用方法

B1=jisuan(A1)

如何在Excel里用正则表达式替换内容

正则表达式,来自于《vba从入门到进阶80集完整版》,具体视频可在网上寻找,或继续追问索取。