Hi,
So I have a list if alphanumeric IDs that I'd like to modify using RegEx to create an in-cell function. I've already enabled Microsoft VBScript Regular Expression 5.5, and I'm using the below code:
I have a list of IDs that use "_" as a delimiter:
Within each ID is a substring that has an alpha and a number between delimiters, ie., "_b82"_, "_b50_", "_a50_", "b01_".
Right now the above code will find the alphanumberic substrings (the string pattern " strPattern = "_[a-zA-Z][0-9]"), but I'd like to just delete the alpha and not anything else. I'm not sure how to make the strReplace value dynamic since the IDs are also dynamic. I'd also like to get rid of the the rest of the text after the last delimter. The desired output in the above example would be:
Is using RegEx the right way to do this, and if so, is the above the right way to go about this? Thanks in advance!
So I have a list if alphanumeric IDs that I'd like to modify using RegEx to create an in-cell function. I've already enabled Microsoft VBScript Regular Expression 5.5, and I'm using the below code:
VBA Code:
Function simpleCellRegex(Myrange As Range) As String
Set regEx = CreateObject("VBScript.RegExp")
Dim strPattern As String
Dim strPattern2 As String
Dim strInput As String
Dim strReplace As String
Dim strOutput As String
strPattern = "_[a-zA-Z][0-9]"
If strPattern <> "" Then
strInput = Myrange.Value
strReplace = "_"
With regEx
.Global = True
.MultiLine = True
.IgnoreCase = False
.Pattern = strPattern
End With
If regEx.test(strInput) Then
simpleCellRegex = regEx.Replace(strInput, strReplace)
Else
simpleCellRegex = "Not matched"
End If
End If
End Function
I have a list of IDs that use "_" as a delimiter:
lchr_01_b82_lc_enus |
lchr_01_b50_lc_enus |
lchr_01_a50_lc_enus |
lchr_01_b01_lc_enus |
Within each ID is a substring that has an alpha and a number between delimiters, ie., "_b82"_, "_b50_", "_a50_", "b01_".
Right now the above code will find the alphanumberic substrings (the string pattern " strPattern = "_[a-zA-Z][0-9]"), but I'd like to just delete the alpha and not anything else. I'm not sure how to make the strReplace value dynamic since the IDs are also dynamic. I'd also like to get rid of the the rest of the text after the last delimter. The desired output in the above example would be:
lchr_01_b82_lc_enus | lchr_01_82_lc |
lchr_01_b50_lc_enus | lchr_01_50_lc |
lchr_01_a50_lc_enus | lchr_01_50_lc |
lchr_01_b01_lc_enus | lchr_01_01_lc |
Is using RegEx the right way to do this, and if so, is the above the right way to go about this? Thanks in advance!