I really don't know why you are using a regular expression here, I find it neither straight forward nor pretty neat.
The string you have provided contains markers for a new segment - since the replacement mark (�
) may not be it's actual value, you may have to adjust the char value:
string test = "TOTAL SALES � EUR � 2'800.0013�000.001�700TOTAL PURCHASEEUR90.007�500.00250.001�444.84MARGIN EUR710.00";
string[] split = test.Split('\uFFFD');
double actualValue = Convert.ToDouble(Regex.Replace(split[2],"[^0-9.]",""));
Console.WriteLine(actualValue);;
Outputs: 2800.0013
for Culture en-us
.
With this way, you also can work more easily with the proper datatype, which would be a double in this example.
Given that this format is static on this point, it's actually legit to rely on the index of the split array.
If you however want to ensure that you're always getting the total sales or that the mask may not be always static, you may even use a simple a substring
/ indexOf
combo:
var start = test.IndexOf("TOTAL SALES");
var dotIndex = test.IndexOf('.',start);
for(int i = dotIndex; i >= 0; i--)
{
if(test[i].Equals(' '))
{
start = i+1;
break;
}
}
string stringValue = test.Substring(start,dotIndex-start);
stringValue = Regex.Replace(stringValue,"[^0-9]","");
Console.WriteLine(Convert.ToInt32(stringValue));
outputs: 2800
.