I have the problem that I can only use one Regex.IsMatch
to validate a string and I have to conditions with regular expressions to be matched for the same string, I've looking and seems that I can use regex conditionals like (?(?=regex)then|else)
to match both regular expressions on the string value, but I can't reach the same result
My actual code working with two regular expressions validation is:
bool flag = false;
if (Regex.IsMatch(alias, "^[a-zñA-ZÑ_0-9-.]{6}[a-zñA-ZÑ_0-9-.]*$"))
{
if (Regex.IsMatch(alias, "[^0-9.-]+"))
{
flag = true;
};
};
And what i want to achieve is something like this:
if (Regex.IsMatch(alias, "(?(^[a-zñA-ZÑ_0-9-.]{6}[a-zñA-ZÑ_0-9-.]*$)([^0-9.-]+))"))
{
// Some code...
};
so if you can give me some guidance or check if my regular expression is right using the conditional in regexp it would appreciated