Hi,
My string looks like this:
myString = "|244_3_Red|244_54_Blue|555_4_Green|"
The first number beside the pipe character is passed in by the user (i.e. 244 or 555). I then need to process the two values between the pipes (i.e. If users passes 244 then process 3 and Red and then 54 and Blue. If user passes in 555 then process 4 and Green.) So far my code looks like this:
Set
objRegExp = New RegExp
objRegExp.IgnoreCase = True
objRegExp.Global = True
objRegExp.Pattern = "\|" &userValue & "_(\d{1,2})_(.*?)\|"
Set matches = objRegExp.Execute(myString)
'Display all of the matches
For Each match in matches
quantity = match.SubMatches(0)
color = match.SubMatches(1)
'If more than one set then store into an array
Next
The problem with this pattern is that the second pipe character (|) get used by the first iteration so anything after does not get matched. In this example if the user passes in 244 then |244_3_Red| only gets matched. |244_54_Blue| does not match because the first pipe was used by the first match so the computer see "244_54_Blue|"and not "|244_54_Blue|".
I can change this to
objRegExp.Pattern =userValue & "_(\d{1,2})_(.*?)\|"
but then values like |5244_45_Blue| get matched.
Any ideas are greatly appreciated.
Thanks!