Last time, in the BBS, I want to separate "1 x bcd_9292" such as strings, such as isolated bcd_9292 number 1 and string content, special thanks to "sysdzw" last time, help me to solve this problem, my last question, did not consider, there are several ways as follows: ABC (1) 1 X CVA_8901, 1 X, 2 X CAD; (2) 1 x cva202 (3) 2 x DEE15043, DEA20201: how is the separation of (4) 2 x DEE150431 DEA20201 x This kind of circumstance can you look at, when there is a (3) because one is not match to the quantity, have prompted; (4) in this case, x digital wrote before went to the front, also hope to have prompt, The regular expression is absolutely powerful, but now I'm in the face of (3) and (4), want to have a prompt, (3) the number of the second sku is artificial reason didn't write; (4) was written, two strings together lead to the number of the second separation not to come out, Thank you all!
CodePudding user response:
Regular expression mainly in the regular search string to data, As for your requirements mainly should be a grammar testing now, recommended the split statements to test the each word is faster,
CodePudding user response:
Private Sub Command1_Click () Call Grammar (" 1 X CVA_8901, ABxC 1 X, 2 X CAD ") End Sub
'* * * * * * * * * * * * * * * * * * * * 'the following only for [digital characters, X X characters] type of grammar tests data, 'here are given syntax compliance, cannot be wrong character period of modification for the compliance of
Private Function Grammar (ByVal strCheck As String) As Boolean Dim I As Single Grammar=True Dim Arr () As String Arr=Split (strCheck, ", ") If UBound (Arr) & gt; 0 Then 'there are multiple data segments For I=0 To UBound (Arr) Grammar=GraSection (Arr (I), I + 1) If Grammar=False Then The Exit For End the If Next The Else 'only a data segment Grammar=GraSection (Arr (0), (1) End the If End the Function
Private Function GraSection (ByVal strCheck As String, ByVal Index As Long) As Boolean GraSection=True Dim Arr () As String Arr=Split (UCase $(strCheck), "X") The Select Case UBound (Arr) Case 0 'indicates that there is an error in the data segment MsgBox "please confirm that the first" & amp; The Index & amp; "The data if there is no X connector!" GraSection=False Case 1 Then If Not IsNumeric (Arr (0)) MsgBox "please confirm that the first" & amp; The Index & amp; "The data of digital section is for digital!" GraSection=False End the If In Case the Else 'indicates that there is an error in the data segment MsgBox "please confirm that the first" & amp; The Index & amp; Article "is the data with the back of the data connection problem!" GraSection=False End the Select End the Function