#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2009
    Posts
    33
    Rep Power
    5

    C# Regex General Help


    Hi,

    I wish to extract the two sections of data inbetween the curly braces from the following code:

    "Links" : [

    {

    "Title" : "Food House", "Url" : "http://foodhouse.com/"

    },

    {

    "Title" : "Foo Foo", "Url" : "http://foofoo.com/"

    }

    ]

    Such that I would have 2 pieces of data:



    "Title" : "Food House", "Url" : "http://foodhouse.com/"



    and



    "Title" : "Foo Foo", "Url" : "http://foofoo.com/"



    I have tried the following code:

    Match match = Regex.Match(links.InnerText, "\"Links\" : \\[ \\{ (.+) \\} \\]");
    MatchCollection matches = Regex.Matches(match.Value, "\\{ (.+) \\}");

    but it doesn't seem to work.



    Any suggestions?
  2. #2
  3. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,692
    Rep Power
    6351
    There are presumably newlines in your data exactly the way you have newlines in your output here. By default, the dot character does not match newlines, you usually have to add a flag of some kind ("m" in perl and PHP).

    This appears to be a standard encoding scheme, possibly JSON? Maybe you can just use C#'s built in parsing.

    -Dan
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

IMN logo majestic logo threadwatch logo seochat tools logo