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

    Join Date
    Jul 2012
    Posts
    5
    Rep Power
    0

    Long regex, need some help


    Hello everyone, I'm trying to pull the following out of a longer line of text and I'm having some troubles finishing.

    I'm trying to get my regex to grab this whole chunk here:
    Code:
    [["ItemFlashlight","ItemWatch","ItemMap","ItemKnife","ItemEtool","ItemGPS","ItemHatchet","ItemCompass","ItemMatchbox","M9SD","ItemFlashlightRed","NVGoggles","Binocular_Vector","ItemToolbox","M4A1_AIM_SD_camo"],["ItemPainkiller","ItemMorphine","ItemSodaPepsi","FoodSteakCooked",["30Rnd_556x45_StanagSD",29],"30Rnd_556x45_StanagSD","30Rnd_556x45_StanagSD","30Rnd_556x45_StanagSD","30Rnd_556x45_StanagSD","30Rnd_556x45_StanagSD",["15Rnd_9x19_M9SD",12],["15Rnd_9x19_M9SD",10],"15Rnd_9x19_M9SD","15Rnd_9x19_M9SD","ItemBandage"]]
    By using the following regex:

    Code:
    \[\[([\w|_|\""|,]*)\],\[([\w|_|\""|,|\[|\]]*)\]\],
    But it only matches up to:
    Code:
    [["ItemFlashlight","ItemWatch","ItemMap","ItemKnife","ItemEtool","ItemGPS","ItemHatchet","ItemCompass","ItemMatchbox","M9SD","ItemFlashlightRed","NVGoggles","Binocular_Vector","ItemToolbox","M4A1_AIM_SD_camo"],["ItemPainkiller","ItemMorphine","ItemSodaPepsi",
    Could anyone tell me what I seem to be missing, I know it has to do when it gets to the items wrapped in '[' style brackets but it's stumping me :/
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Hi,

    A regex makes absolutely no sense in this case. This looks like a specific data format (JSON?), so you should use a proper parser. Or maybe you can do a simple text search?

    Regular expressions are not the solution to every problem. Patterns like this with nested expressions are extremely difficult to describe with regexes -- or even not at all.

    So it's very important to choose the right tool. Regular expressions are only appropriate for simple patterns like a date that can be described as a sequence of characters.

    // I see that I've made the exact suggestion in your last thread. So you're really in love with regexes.
    Last edited by Jacques1; August 20th, 2012 at 03:11 PM.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    5
    Rep Power
    0
    Originally Posted by Jacques1
    Hi,

    A regex makes absolutely no sense in this case. This looks like a specific data format (JSON?), so you should use a proper parser. Or maybe you can do a simple text search?

    Regular expressions are not the solution to every problem. Patterns like this with nested expressions are extremely difficult to describe with regexes -- or even not at all.

    So it's very important to choose the right tool. Regular expressions are only appropriate for simple patterns like a date that can be described as a sequence of characters.

    // I see that I've made the exact suggestion in your last thread. So you're really in love with regexes.
    lol no, I'm just new to this area, and I'm using a vb.net environment.

    Since you suggest a different method, are there any tutorials you can link me to or possibly a practical example.
  6. #4
  7. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    I can't give you practical examples without even knowing where this comes from.

    If it's actually JSON, just look for a JSON parser for VB.net. If it's a different format, look for a parser for this format.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".

IMN logo majestic logo threadwatch logo seochat tools logo