Caleeco
Well-known Member
- Joined
- Jan 9, 2016
- Messages
- 980
- Office Version
- 2010
- Platform
- 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 pattern I have made is:
The full function:
Is there a cleaner pattern I can use?
Kind Regards
Caleeco
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