This is my first attempt to use regular expression.
What I want to archieve is to convert this string:
" <Control1 x:Uid="1" />
<Control2 x:Uid="2" /> "
to
" <Control1 {1} />
<Control2 {2} /> "
Basically, convert x:Uid="n" to {n}, where n represents an integer.
What I thought it would work (of course it doesn't) is like this:
string input = " <Control1 x:Uid="1" />
<Control2 x:Uid="2" /> ";
string pattern = "\b[x:Uid=\"[\d]\"]\w+";
string replacement = "{}";
Regex rgx = new Regex(pattern);
string result = rgx.Replace(input, replacement);
Or
Regex.Replace(input, pattern, delegate(Match match)
{
// do something here
return result
});
I'm struggling to define the pattern and replacement string. I'm not sure if I'm in the right direction to solve the problem.
Uids can only be exactly one digit long? Because\dmatches exactly one digit.