G
Guest
At the first glance, this problem seems to be easy, but I found it not:
There is a regex, that is known to be valid, but of which I have no control
(in comes from a public XML schema). I need to evaluate an input string to
make sure it matches the regex.
The most obvious code apprears to be something like this (as Regex class
only has substring search methods, and no exact match methods):
Match m = myRegex.Match(inputString);
if (m.Success && m.Length == inputString.Length)
{
// Some code...
}
However, there is a problem. For example, if the regex is "a|ab", the input
string "ab" should match it, but is will fails the above test (because
higher-priority substring "a" will be matched).
Currently, I can find no fix/workaround: since modifying regex is not an
option changing "a|ab" to "ab|a" is not an acceptable solution. Also, the
code must be generic with regard to regex, so inserting ||inputString=="ab"
into the 'if' statement is not an acceptable solution either.
Can anyoune suggest a way to
There is a regex, that is known to be valid, but of which I have no control
(in comes from a public XML schema). I need to evaluate an input string to
make sure it matches the regex.
The most obvious code apprears to be something like this (as Regex class
only has substring search methods, and no exact match methods):
Match m = myRegex.Match(inputString);
if (m.Success && m.Length == inputString.Length)
{
// Some code...
}
However, there is a problem. For example, if the regex is "a|ab", the input
string "ab" should match it, but is will fails the above test (because
higher-priority substring "a" will be matched).
Currently, I can find no fix/workaround: since modifying regex is not an
option changing "a|ab" to "ab|a" is not an acceptable solution. Also, the
code must be generic with regard to regex, so inserting ||inputString=="ab"
into the 'if' statement is not an acceptable solution either.
Can anyoune suggest a way to