I have a string array
string [] ar = { "net" , "com" , "org"};
and I want the label writes "true" when the user enter a website example ends with a string in the array
I tried this:
private void timer1_Tick(object sender, EventArgs e)
{
foreach ( string ex in ar)
{
if (Regex.IsMatch(txtbox.Text, @"^(www\.)([\w]+)\.(" + ex + ")$"))
{
lbl.Text = "True";
}
else
{
lbl.Text = "False";
}
}
}
When I write for example "www.google.com", the label still writes false. Only when I write "www.google.org" the label writes true.
lbl.Text = ar.Any(ex => Regex.IsMatch(txtbox.Text, @"^(www\.)([\w]+)\.(" + ex + ")$"))) ? "True" : "False";insteadEndWithshould be really enough, regex is not necessary.