I am looking for a regular expression where i can extract portion of a string that meets the criteria.
string lookup "The length is 32.00 mm".
I would like to be able to get "32.00". Basically the first numeric value before " mm ". in a burte force kind of way, it can be done like this:
string test = "The length is 32.00 mm";
int idx = test.IndexOf(" mm ") - 1;
int endIdx = idx;
while (idx > 0)
{
Char c = test.ElementAt(idx);
if (Char.IsDigit(c) == false && c != '.')
{
string data = test.Substring(idx + 1, endIdx - idx + 1);
break;
}
idx--;
}
Do you have any better logic?
I can split the string by space and pick up the entry before the "mm" slot.
Thanks,
[\d.]+(?=\s+mm)might satisfy