开发者

Regex works differently on different computer

开发者 https://www.devze.com 2023-01-07 06:29 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消