var flashvars = {
        "client.allow.cross.domain" : "0",
        "client.notify.cross.domain" : "1",
};


出于某些奇怪的原因,我们不希望使用此代码(在C#中)进行解析。

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("\" : \"", "=") + "&";
         }
    }
}

最佳答案

使用RegexOptions.SingleLine而不是RegexOptions.Multiline

RegexOptions.Singleline


  指定单行模式。更改点(。)的含义,使其匹配每个字符(而不是\ n以外的每个字符)。


http://msdn.microsoft.com/en-us/library/443e8hc7(vs.71).aspx

10-08 13:01