views:

69

answers:

1

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 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"
+4  A: 

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.

Matthew Flaschen
Technically, this wasn't *my* problem, but it's a great answer to my question.
Daniel Rasmussen