Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET Regex pattern?

Tags:

c#

.net

regex

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

For some strange reason does not want to be parsed with this code (in 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("\" : \"", "=") + "&";
         }
    }
}
like image 567
Scott Avatar asked Jun 14 '26 19:06

Scott


1 Answers

Use RegexOptions.SingleLine rather than RegexOptions.Multiline

RegexOptions.Singleline

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

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

like image 71
vfilby Avatar answered Jun 16 '26 10:06

vfilby



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!