Regex Problem
-
Hi there everyone, I'm trying to do what is basically a String.Replace but not quite. I have a string e.g. "{Team}/{Team} Index" and a hashtable of replacement string values, e.g. "Wigan Athletic", "Manchester United". I need to loop through the hashtable and replace the first occurrence of the substring "{Team}" with "Wigan Athletic", and then on the next iteration replace the substring "{Team}" with "Manchester United". The problem I've got is (obviously) String.Replace replaces all occurrences of "{Team}" the first time through, and using regex every expression I write seems to select both occurrences. Is there a way to stop the regex matching after hitting the first match? Or otherwise some method of doing this that I'm just missing? Any help much appreciated :) Thanks, James
-
Hi there everyone, I'm trying to do what is basically a String.Replace but not quite. I have a string e.g. "{Team}/{Team} Index" and a hashtable of replacement string values, e.g. "Wigan Athletic", "Manchester United". I need to loop through the hashtable and replace the first occurrence of the substring "{Team}" with "Wigan Athletic", and then on the next iteration replace the substring "{Team}" with "Manchester United". The problem I've got is (obviously) String.Replace replaces all occurrences of "{Team}" the first time through, and using regex every expression I write seems to select both occurrences. Is there a way to stop the regex matching after hitting the first match? Or otherwise some method of doing this that I'm just missing? Any help much appreciated :) Thanks, James
There are several versions of the Regex Replace method available. One allows you to specify the maximum number of replacements to make.
-
There are several versions of the Regex Replace method available. One allows you to specify the maximum number of replacements to make.
-
Hi there everyone, I'm trying to do what is basically a String.Replace but not quite. I have a string e.g. "{Team}/{Team} Index" and a hashtable of replacement string values, e.g. "Wigan Athletic", "Manchester United". I need to loop through the hashtable and replace the first occurrence of the substring "{Team}" with "Wigan Athletic", and then on the next iteration replace the substring "{Team}" with "Manchester United". The problem I've got is (obviously) String.Replace replaces all occurrences of "{Team}" the first time through, and using regex every expression I write seems to select both occurrences. Is there a way to stop the regex matching after hitting the first match? Or otherwise some method of doing this that I'm just missing? Any help much appreciated :) Thanks, James
Is this an old question or a new one? Or has your account been hacked?
-
Is this an old question or a new one? Or has your account been hacked?
-
Dunno. It showed up in moderation yesterday.