Regex pattern to match and replace a version number in a string c#
I want to find replace Version number from a string by using Regex 开发者_JAVA技巧in c#.
string is like this:
string val="AA.EMEA.BizTalk.GroupNettingIntegrations, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a86ac114137740ef";
Is any one can help me to solve this problem.
It seems to me you could easily accomplish this without a regex and have your code be easier to read:
string components[] = someAssemblyFullyQualifiedName.Split(new char[] { ',' }, StringSplitOptions.IgnoreEmptyEntires);
if(components.Length > 1)
components[1] = "Version=2.0.0.0"; // whatever you want to replace with
string newFullyQualifiedName = string.Join(",", components):
The following Regex will do the replace you are looking for.
string val = "AA.EMEA.BizTalk.GroupNettingIntegrations, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a86ac114137740ef";
val = Regex.Replace(val, @"Version=[\d\.]+", "Version=2.0.0.0");
EDIT: You can also use look-behind Regex functionality if you don't want to have to put the "Version=" in the replacement string. If you are looking for that, add a comment and I'll draw it up.
精彩评论