I'm writing a program which uses regex to match incoming data. The regex works on the computer I'm coding on, but it doesn't work on the client computer I'm testing on. It works on my computer in debug mode, release mode, and being run straight from the bin. What could possibly make a regex work开发者_StackOverflow社区 differently?
Regex:
const string _pattern
= @"^(?:\x02)?([A-Z])(ST)([WS])([1-9])([ AM])([ NSEWIO])([- ]\d{6})([ M])([1CPN])(\w)?(?:\x0D)?$";
static readonly Regex _regex
= new Regex(_pattern, RegexOptions.IgnoreCase | RegexOptions.Compiled);
String:
@"ASTS2MI-000020 C0"
Probably you need CultureInvariant:
static readonly Regex _regex
= new Regex(_pattern, RegexOptions.CultureInvariant | RegexOptions.IgnoreCase | RegexOptions.Compiled);
As explained at Performing Culture-Insensitive Operations in the RegularExpressions Namespace, by default case-insensitive matching takes into account Thread.CurrentCulture
.
精彩评论