I have the following code which works fine but i need to replace the site address with a variable…
string url = HttpContext.Current.Request.Url.AbsoluteUri; // Get the URL
bool match = Regex.IsMatch(url, @"(^|\s)http://www.mywebsite.co.uk/index.aspx(\s|$)");
I have tried the following but it doesn’t work, any ideas???
string url = HttpContext.Current.Request.Url.AbsoluteUri; // Get the URL
string myurl = "http://www.mywebsite.co.uk/index.aspx";
bool match = Regex.IsMatch(url, @"(^|\s)"+myurl+"(\s|$)");
You are missing a
@:The reason that you need the extra
@is because the@applies only to the string literal immediately following it. It does not apply to the entire rest of the line.You should also consider escaping your URL: