I’m trying to replace all the text in a string between the pattern “&CC[number]:[number]” and replace it with a “==”.
Here is the string.
"T &CC3:5 Q8 Party/ Self-Identify&CC6:8 Male&CC9:11 Female&CC12:15 Q1 Vote"
This is what I need it to look like
I know I need to loop through this string but I’m not sure the best way to set this up.
Dim stringOne As String Dim regexOne As Object Set regexOne = New RegExp regexOne.Pattern = "([Q])+[0-9]" regexOne.Global = False stringOne = "T &CC3:5 Q8 Party/ Self-Identify&CC6:8 Male&CC9:11 Female&CC12:15 Q1 Vote" Debug.Print regexOne.Replace(stringOne, "==") End Sub
I have also explored using this regular expression
regexOne.Pattern = "([&])+[C]+[C]+[0-9]+[:]+[0-9]"
I plan to eventually set the variable stringOne to
You could simplify the pattern a bit and use a capturing group and a positive lookahead
(Capture group 1
&CC1+ digits, : and 1+ digits
.*?Match 0+ times any char except a newline non greedy
(?=&C|$)Positive lookahead, assert what is directly on the right is either
&Cor the end of the string
In the replacement use the first capturing group followed by