var flashvars = {
"client.allow.cross.domain" : "0",
"client.notify.cross.domain" : "1",
};
由於一些奇怪的原因不是想要解析此代碼(在C#中)。.NET正則表達式模式?
private void parseVariables() {
String page;
Regex flashVars = new Regex("var flashvars = {(.*?)}", RegexOptions.Multiline | RegexOptions.IgnoreCase);
Regex var = new Regex(@"""(.*?)"",", RegexOptions.Multiline | RegexOptions.IgnoreCase);
Match flashVarsMatch;
MatchCollection matches;
String vars = "";
if (!IsLoggedIn)
{
throw new NotLoggedInException();
}
page = Request(URL_CLIENT);
flashVarsMatch = flashVars.Match(page);
matches = var.Matches(flashVarsMatch.Groups[1].Value);
if (matches.Count > 0)
{
foreach (Match item in matches)
{
vars += item.Groups[1].Value.Replace("\" : \"", "=") + "&";
}
}
}
@Scott:只是迂腐:C#是具有在所有(不同的JavaScript)沒有正則表達式支持的編程語言。 OTOH,.NET Framework有System.Text.RegularExpressions.Regex類。 – 2010-04-29 19:41:56