加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – .NET正则表达式模式?

发布时间:2020-12-16 01:35:46 所属栏目:百科 来源:网络整理
导读:var flashvars = { "client.allow.cross.domain" : "0","client.notify.cross.domain" : "1",}; 由于某些奇怪的原因,不希望使用此代码进行解析(在C#中). private void parseVariables() { String page; Regex flashVars = new Regex("var flashvars = {(.*?)
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

Specifies single-line mode. Changes the meaning of the dot (.) so it matches every character (instead of every character exceptn).

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读