Why does my Regex.Replace string contain the replacement value twice?

前端 未结 1 1077
忘了有多久
忘了有多久 2020-12-03 23:12

I have the following string: aWesdE, which I want to convert to http://myserver.com/aWesdE.jpg using Regex.Replace(string, string, string, Re

相关标签:
1条回答
  • 2020-12-04 00:01

    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

    0 讨论(0)
提交回复
热议问题