I'm not overly strong in regex and trying to determine if this is possible...
I have data coming in alphanumeric which could be defined a number of ways:
100
NW100
W100
100NW
100W
(may not always be W/NW - just an example of letters)
I would like to split the data into variables to hold the alpha and numeric separately. Using regex groups, I have this so far:
var numAlpha = new Regex("(?<Alpha>[a-zA-Z]*)(?<Numeric>[0-9]*)");
var startMatch = numAlpha.Match(myDataString);
var alpha = startMatch.Groups["Alpha"].Value;
int number = int.Parse(startMatch.Groups["Numeric"].Value);
This doesn't work for all cases, particularly when the alpha is at the end (e.g. 100W).
I would like it to check the beginning AND end of the string for the alphabetic part and still store it into the same alpha variable.
I was able to create a third group named Alpha2
(?<Alpha>[a-zA-Z]*)(?<Numeric>[0-9]*)(?<Alpha2>[a-zA-Z]*)
but would like to keep it to two groups (and two variables) if it is possible. Any advice appreciated.
