I'm parsing decimal values with a decimal separator using regex, that are in US format, like: 2.56
But my system's culture decimal separator is set to a comma, so when I use the decimal class \d, the regex fails to recognize "2.56" as a valid decimal number.
I would like to stick to the \d for the sake of readability and simplicity. Can I force it to recognize dot as a decimal separator?
When using float.TryParse(), I can enforce it to use dot as a decimal separator:
var usCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
float.TryParse(text, System.Globalization.NumberStyles.Number, usCulture, out s )
Can I do something similar for regex?
I tried changing current thread's culture:
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
but it doesn't seem to affect the regex, it still expects comma as a decimal separator.