使用.NET框架,我试图用单斜杠替换字符串中的双斜线字符,但它似乎是删除一个额外的字符,我不知道为什么。正则表达式替换帮助
我有一个字符串:
http://localhost:4170/RCRSelfRegistration//Default.aspx
我的正则表达式是:
[^(://|:\\\\)](\\\\|//|\\/|/\\)
,返回值是:
http://localhost:4170/RCRSelfRegistratio/Default.aspx
你可以看到,在RCRSelfRegistration n个已除去。我不知道为什么。
/// <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;
}
我明白你的意思了。我已将字符串简化为“[^:](\\\\ | | // | \\/|/\\)”,但您能告诉我零宽度后视的语法吗? – Jeremy 2009-01-27 17:46:22
现在遍布各地。 =) – Instantsoup 2009-01-27 17:47:53