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

    Join Date
    Jul 2012
    Posts
    5
    Rep Power
    0

    Finding 'coordinates'


    I'm using vb.net in the end but testing my Regex with Expresso and regexhero.net

    Anyway, I'm reading from the following line trying to grab data that's highlighted.

    Code:
    1:11:49 "READ/WRITE: ['PASS',false,'18675240',[29,[6666.84,2344.13,0.23523]],[["ItemFlashlight","revolver_EP1","ItemWatch"],["2Rnd_shotgun_74Slug","ItemSodaPepsi","FoodCanBakedBeans","ItemPainkiller","ItemWaterbottle","HandRoadFlare","HandChemRed","ItemSodaCoke","ItemHeatPack","HandChemBlue","ItemSodaPepsi","FoodCanFrankBeans","6Rnd_45ACP","ItemBandage","ItemBandage","6Rnd_45ACP","6Rnd_45ACP","ItemBandage","6Rnd_45ACP","6Rnd_45ACP"]],["DZ_Patrol_Pack_EP1",[[],[]],[[],[]]],[615,619,619],"Survivor2_DZ",0.93]"
    The following regex SHOULD work but for some reason I can't get it to.

    Code:
    /\[(\d+)\,\[(-?\d+)\.\d+\,(-?\d+)\.\d+,([\d|.|-]+)\]\]/
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

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

    And what exactly doesn't work? Does the regex not even parse? Do you get no matches? Are the capturing groups returning the "wrong" results?

    The regex actually does work in Ruby's regex engine, returning

    Code:
    whole match: 
    "[29,[6666.84,2344.13,0.23523]]" 
    group 1:
    "29"
    group 2:
    "6666"
    group 3:
    "2344"
    group 4:
    "0.23523"
    The only problem I see is that you're using character classes wrong:
    Code:
    [\d|.|-]
    A character class consists of single characters, so the "|" is interpreted as a literal character. Since it's occuring twice, this might lead to problems in some regex engines.

    And the escaping of the commas is unnecessary. This isn't a special character in regexes.

    By the way, is this a common data format? Looks a bit like JSON. If it is, then use a parser for that, not regexes.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    5
    Rep Power
    0
    I found the error. Just a mistake of overlooking actually.

    I had to use
    \[(\d+)\,\[(-?\d+)\.\d+\,(-?\d+)\.\d+,([\d|.|-]+)\]\]
    instead
  6. #4
  7. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Except that you still got the character class wrong...

IMN logo majestic logo threadwatch logo seochat tools logo