Consider a string that looks like this:
RR1 S5 C92
This a rural route address for out-of-town mail delivery: Rural Route, Site, Compartment. Each letter is followed by a number and a space. Usually one to three digits long, but you never know how many numbers it could be! If the user is lazy, they may have entered zero, one or many spaces.
Question:
What regex would YOU use to determine if a given string matches this pattern?
Its usage would be something like this:
string ruralPattern; //a regex pattern here
bool isRural = Regex.Match(someString, ruralPattern);
Update: Thank you for your suggestions! Performance and usage will be within a static method in an assembly to be called from a web service. The strings being checked against this pattern will be max 50 characters. The method will be called roughly once every 5 seconds. Any suggestions on keeping it static? Much appreciated!
This should work:
or as per other comment
What it all means:
There might be a more elegant solution but this is pretty easy to read.
Edit: Updated to include input from some of the comments