Regular Expression TidyUp

Caleeco

Well-known Member
Joined
Jan 9, 2016
Messages
980
Office Version
  1. 2010
Platform
  1. Windows
Hello,

I have just waded into the world of Regular Expressions. I have created a Function (with some googling) that will check if a pattern exists at the start of a string.

The function works as anticipated but Im not sure if this pattern is as clean as it could be? The Pattern is

A11_1111AAAA_111_111
  • The A can be any letter [a-z]
  • The 1 can be any digit [0-9]

The pattern I have made is:
Code:
"^[a-z](\d{2})(\_)(\d{4}[a-z]{4})(\_)(\d{3})(\_)(\d{3})"

The full function:

Code:
Sub TestExpr()
    MsgBox executeMethodRegEx("^[a-z](\d{2})(\_)(\d{4}[a-z]{4})(\_)(\d{3})(\_)(\d{3})", "B01_0092DARK_002_000xt(C18)")
End Sub

Function executeMethodRegEx(regPattern As String, regString As String)
    Dim rgx As Object
    Set rgx = CreateObject("VBScript.RegExp")
    Dim allMatches As Object, item As Object
    With rgx
        .Pattern = regPattern
        .Global = True
        .IgnoreCase = True
        .MultiLine = True
    End With
    
    If rgx.Test(regString) Then
        executeMethodRegEx = True
    Else
        executeMethodRegEx = False
    End If
End Function

Is there a cleaner pattern I can use?

Kind Regards
Caleeco
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

Forum statistics

Threads
1,224,815
Messages
6,181,135
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top