I have tried to detect the same on regex101, but when I try to run the excel-VBA code it fails to detect.
I have been trying to detect and group the Following Text:
Test A1 (III’15) 270 10/12 ABC/DEF PNR AVC
Test Asd(II’05) 300 11/12 RtF/ZXC PNR NKL
Test 33 (I’01) PIL 11/12 KNP/ILO IL 90.5 FX - NO
Test 4 (IIII’10) 270 11-12/12 JKI/IOP PNR RPTD - RPTD
My Pattern: ([\w ]+)\s+([\w()\’\’ ]+)\s+(\w+)\s+([\w/-]+)\s+([\w/+]+)\s+([\w.\s]+)\s+([\w -]+)
My Code:
Private Sub splitUpRegexPattern()
Dim regEx As New RegExp
Dim strPattern As String
Dim strInput As String
Dim strReplace As String
Dim Myrange As Range
Set Myrange = ActiveSheet.Range("A1:A63")
For Each C In Myrange
strPattern = "([\w ]+)\s+([\w\(\)\’\’ ]+)\s+(\w+)\s+([\w\/\-]+)\s+([\w\/\+]+)\s+([\w\.\s]+)\s+([\w \-]+)"
If strPattern <> "" Then
strInput = C.Value
'strReplace = "$1"
With regEx
.Global = False
.MultiLine = False
.IgnoreCase = True
.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")
C.Offset(0, 3) = regEx.Replace(strInput, "$3")
C.Offset(0, 4) = regEx.Replace(strInput, "$4")
C.Offset(0, 5) = regEx.Replace(strInput, "$5")
C.Offset(0, 6) = regEx.Replace(strInput, "$6")
C.Offset(0, 7) = regEx.Replace(strInput, "$7")
Else
C.Offset(0, 1) = "(Not matched)"
End If
End If
Next
End Sub
I need to group then as
Group1: (Test A1) Group 2: ((III’15)) Group 3: (270) Group 4: (10/12) Group 5: (ABC/DEF) Group 6: (PNR) Group 7:(AVC)
([\w\s]*)\s*(\([\S\s]+?\))\s*([\w\d]+)\s*([\d|\-|/]+)\s*([\w|/]+)\s*(\w+\s?(?:\d|\.)*)\s*(\w+(?:\s?-\s\w+)?)