Having read this very useful post on how to use RegEx within MS Excel, I am now stuck in generating the required expression to cover following scenarios - Any help appreciated.
Objective: I want to be able to split strings like the ones below:
Example 1:
AB12345|AB56789x89402
--->AB12345
AB56789
89402
(each of the three to be stored in different cell and the total number of sub-strings is not known in advance, could be from 0 to 10)
Example 2:
#AB03925#
to be stored asAB03925
Example 3:
(ABC-SR-XYZ)|(ABC-XYZ)
to be stored asABCXYZ
Is it possible to have all of the above examples handled through a single RegEx?
So far I have created the following which partially handles cases like example 1:
strPattern = "(^[A-Z][A-Z][0-9]{5})([|]*[A-Z][A-Z][0-9]{5})"
If strPattern <> "" Then
strInput = C.Value
With regEx
.Global = True
.MultiLine = True
.IgnoreCase = False
.Pattern = strPattern
End With
If regEx.Test(strInput) Then
C.Offset(0, 1) = regEx.Replace(strInput, "$1")
C.Offset(0, 2) = regEx.Replace(strInput, "$2")
End If
End If
However I still do not know how to get rid of the pipe (|) when printing those two strings separately.