A
ACalafiore
Guest
Hi,
I'm having a problem using the Regex class to match an input.
const string ConfigurationRegEx = @"^(?<quartzFreq>quartz freq[.][(]KHz[)]:\d{4,6})" + @"\s*\r?\n" +
@"(?<clockFreq>clock freq[.][(]KHz[)]:\d{4,7})" + @"\s*\r?\n" +
@"(?<ramWaitStates>RAM wait states:\d)" + @"\s*\r?\n" +
@"(?<romWaitStates>ROM wait states:\d)" + @"\s*\r?\n" +
@"(?<cache>disable cache:\d)" + @"\s*\r?\n" +
@"(?<type>card type:\d{3})" + @"\s*\r?\n" +
@"(?<version>card version:\d)" + @"\s*\r?\n" +
@"(?<keyboard>keyboard type:\d)" + @"\s*\r?\n" +
@"(?<touchscreen>touchscreen type:\d)" + @"\s*\r?\n" +
@"(?<rotation>screen rotation:\d)" + @"\s*\r?\n" +
@"(?<stationNumber>RS485 station number:\d)" + @"\s*\r?\n" +
@"(?<IP>IP address\d{1,3}[.]){3}\d{1,3})" + @"\s*\r?\n" +
@"(?<MAC>MAC address[0-9A-F]{2}[:]){5}([0-9A-F]{2}))" + @"\s*\r?\n" +
@"(?<serviceTag>service tag:\d{1,9})" + @"\s*\r?\n" +
@"(?<LCD>LCD:\d{2,3})" + @"\s*\r?\n*";
Regex regex = new Regex(ConfigurationRegEx);
That is my Regex. I would like to know where it failed but using the Match method I get the Groups collection filled only on success. If the match fails I only get one empty group.
The only method I found is to check the input line by line to see if it matches with the requested line Regex.
Eg.:
Check if line0 matches with <quartzFreq> group,
check if line1 matches with <clockFreq> group,
...,
and so on.
Doing so I need to have multiple Regex checks instead of only one. Is there a way to get where the Regex failed?
Thanks
Continue reading...
I'm having a problem using the Regex class to match an input.
const string ConfigurationRegEx = @"^(?<quartzFreq>quartz freq[.][(]KHz[)]:\d{4,6})" + @"\s*\r?\n" +
@"(?<clockFreq>clock freq[.][(]KHz[)]:\d{4,7})" + @"\s*\r?\n" +
@"(?<ramWaitStates>RAM wait states:\d)" + @"\s*\r?\n" +
@"(?<romWaitStates>ROM wait states:\d)" + @"\s*\r?\n" +
@"(?<cache>disable cache:\d)" + @"\s*\r?\n" +
@"(?<type>card type:\d{3})" + @"\s*\r?\n" +
@"(?<version>card version:\d)" + @"\s*\r?\n" +
@"(?<keyboard>keyboard type:\d)" + @"\s*\r?\n" +
@"(?<touchscreen>touchscreen type:\d)" + @"\s*\r?\n" +
@"(?<rotation>screen rotation:\d)" + @"\s*\r?\n" +
@"(?<stationNumber>RS485 station number:\d)" + @"\s*\r?\n" +
@"(?<IP>IP address\d{1,3}[.]){3}\d{1,3})" + @"\s*\r?\n" +
@"(?<MAC>MAC address[0-9A-F]{2}[:]){5}([0-9A-F]{2}))" + @"\s*\r?\n" +
@"(?<serviceTag>service tag:\d{1,9})" + @"\s*\r?\n" +
@"(?<LCD>LCD:\d{2,3})" + @"\s*\r?\n*";
Regex regex = new Regex(ConfigurationRegEx);
That is my Regex. I would like to know where it failed but using the Match method I get the Groups collection filled only on success. If the match fails I only get one empty group.
The only method I found is to check the input line by line to see if it matches with the requested line Regex.
Eg.:
Check if line0 matches with <quartzFreq> group,
check if line1 matches with <clockFreq> group,
...,
and so on.
Doing so I need to have multiple Regex checks instead of only one. Is there a way to get where the Regex failed?
Thanks
Continue reading...