3
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("\" : \"", "=") + "&";
         }
    }
}
1
  • @Scott: just to be pedantic: C# is a programming language which has no regex support at all (unlike JavaScript). OTOH, the .NET Framework has the System.Text.RegularExpressions.Regex class. Commented Apr 29, 2010 at 19:41

2 Answers 2

5

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

Sign up to request clarification or add additional context in comments.

1 Comment

Problem fixed. Thanks vfilby and Max Shawabkeh.
2

You need to use the Singleline flag. Otherwise a period doesn't match new lines. MultiLine is used to make ^ and $ match at start/end of lines. Also, you need to escape the curly brackets:

Regex flashVars = new Regex(@"var flashvars = \{(.*?)\}", RegexOptions.Singleline | RegexOptions.IgnoreCase);

5 Comments

I cannot seem to find the DotAll flag, are you sure it's a valid RegexOption for C# .NET?
DotAll is known as single line, see this answer: stackoverflow.com/questions/2740176/net-regex-pattern/….
Fixed. Used to Python's naming. The .NET equivalent is Singleline.
You have to escape the backslash for the c# string with another one, so it should be "var flashvars = \\{(.*?)\\}"
@Philip Daubmeier: Made the string raw.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.