Regex replace help
- by Jeremy
Using the .NET framework, I'm trying to replace double slash characters in a string with a single slash, but it seems to be removing an extra character and I don't know why.
I have a string:
http://localhost:4170/RCRSelfRegistration//Default.aspx
My regex is:
[^(://|:\\\\)](\\\\|//|\\/|/\\)
And the return value is:
http://localhost:4170/RCRSelfRegistratio/Default.aspx
You can see that the n in RCRSelfRegistration has been removed. I am not sure why.
/// <summary>
/// Match on double slashes (//, \\, /\, \/) but do not match :// or :\\
/// </summary>
private const string strMATCH = @"[^(://|:\\\\)](\\\\|//|\\/|/\\)";
/// <summary>
/// Replace double slashes with single slash
/// </summary>
/// <param name="strUrl"></param>
/// <returns></returns>
public static string GetUrl(string strUrl)
{
string strNewUrl
System.Text.RegularExpressions.Regex rxReplace =
new System.Text.RegularExpressions.Regex(strMATCH);
strNewUrl = rxReplace.Replace(strUrl, "/");
return strNewUrl;
}