I have the following situation
I need to match something like
abc
or
abc
This means that the last parameter is optional.
I have already done the regex and it works, but since I don’t know how to make it optional, from now on I use two different regExpression.
public static bool ValidFn(string input)
{
string regEx1 = @"^[a-zA-Z]*#\([A-Za-z0-9]+,[-|+]?\d+[dwmqy],[-|+]?\d+[dwmqy]\)";
string regEx2 = @"^[a-zA-Z]*#\([A-Za-z0-9]+,[-|+]?\d+[dwmqy]\)";
Regex r1 = new Regex(regEx1);
Regex r2 = new Regex(regEx2);
Match m1 = r1.Match(input);
Match m2 = r2.Match(input);
if (m1.Success || m2.Success) return true;
else return false;
}
How can I make regExp1 as optional so that I can eliminate the use of regExp2.
thank
source
share