Why does my Regex.Replace string contain the replacement value twice?
.net, c#, regex
Solution
There are actually 2 matches in your Regex. You defined your match like this:
string match = "(.*)";
It means match zero or more characters, so you have 2 matches - empty string and your text. In order to fix it change the pattern to
string match = "(.+)";
It means match one or more characters - in that case you will only get a single match
Problem
I have the following string: `aWesdE`, which I want to convert to `http://myserver.com/aWesdE.jpg` using `Regex.Replace(string, string, string, RegexOptions)` Currently, I use this code: ``` string input = "aWesdE"; string match = "(.*)"; string replacement = "http://myserver.com/$1.jpg"; string output = Regex.Replace(input, match, replacement, RegexOptions.IgnoreCase | RegexOptions.Singleline); ``` The result is that output is ending up as: `http://myserver.com/aWesdE.jpghttp://myserver.com/.jpg` So, the replacement value shows up correctly, and then appears to be appended again - very strange. What's going on here?