Regular Expression help needed

Discussion in 'Ruby' started by Raju Alluri, Nov 20, 2008.

  1. Raju Alluri

    Raju Alluri Guest

    Hi,
    I have the following text as a string. Can someone tell me a way to
    extract the Args array in to different key value pairs as listed in the
    example ?

    Request={Identities={ImmedCaller={Name=unknown,
    SubjectID=abcd1:sid:00000000-0000-0000-0000-000000000000}},
    Args=[{adpage=1, useragent=NORMAL, q=Digital Camera, adtest=off,
    searchalias=aps, mkt=us, ch=all-product-search, nodeList=, lang=en,
    adcount=a3b0c3, ip=110.155.15.777}], Service=WebSearchClientService,
    Metadata={GUID=0Q1C11GKER2MEDM5RQDY, Domain=prod,
    Host=woe-us-preprod-gp-5106.iad5.xyz.com, AppVersion=*, UserName=nobody,
    ClientExit=/gp/search/construct-application-context.mi
    [retail]:.SECOND_PREPARE, ProcessID=23480, TTL=1.0, Sandbox=*,
    Priority=1.0, DeploymentID=70026525, EnvName=RetailWebsite/US,
    DepartureTimestamp=Mon Nov 10 17:30:58 GMT 2008, Realm=USXYz,
    AppName=gurupa, ClientEntry=/gp/search},
    Shared={sessionID=nNo5yA.xUpGCpgbhuaVn8zG2xXM_,
    clientID=168v1upXnQTYihGa9iDnty-o9z4_,
    sessionIDPlain=176-2496192-6342626, customerIDPlain=A2LOKEDOEV0ZP5,
    customerID=MHuB7vXfQZbKXH9-U7M7ZZfvy3Q_,
    clientIDPlain=189-5451931-2768662}, Method=WebSearch}

    eg:
    adpage=1
    useragent=NORMAL
    q=Digital Camera
    adtest=off
    mkt=us
    ch=all-product-search
    adcount=a3b0c3


    Thanks in Advance.
    Raju
    --
    Posted via http://www.ruby-forum.com/.
    Raju Alluri, Nov 20, 2008
    #1
    1. Advertising

  2. Raju Alluri

    Diogo Lisboa Guest

    On Thu, Nov 20, 2008 at 6:34 PM, Raju Alluri <> wrote:
    > Hi,
    > I have the following text as a string. Can someone tell me a way to
    > extract the Args array in to different key value pairs as listed in the
    > example ?
    >
    > Request={Identities={ImmedCaller={Name=unknown,
    > SubjectID=abcd1:sid:00000000-0000-0000-0000-000000000000}},
    > Args=[{adpage=1, useragent=NORMAL, q=Digital Camera, adtest=off,
    > searchalias=aps, mkt=us, ch=all-product-search, nodeList=, lang=en,
    > adcount=a3b0c3, ip=110.155.15.777}], Service=WebSearchClientService,
    > Metadata={GUID=0Q1C11GKER2MEDM5RQDY, Domain=prod,
    > Host=woe-us-preprod-gp-5106.iad5.xyz.com, AppVersion=*, UserName=nobody,
    > ClientExit=/gp/search/construct-application-context.mi
    > [retail]:.SECOND_PREPARE, ProcessID=23480, TTL=1.0, Sandbox=*,
    > Priority=1.0, DeploymentID=70026525, EnvName=RetailWebsite/US,
    > DepartureTimestamp=Mon Nov 10 17:30:58 GMT 2008, Realm=USXYz,
    > AppName=gurupa, ClientEntry=/gp/search},
    > Shared={sessionID=nNo5yA.xUpGCpgbhuaVn8zG2xXM_,
    > clientID=168v1upXnQTYihGa9iDnty-o9z4_,
    > sessionIDPlain=176-2496192-6342626, customerIDPlain=A2LOKEDOEV0ZP5,
    > customerID=MHuB7vXfQZbKXH9-U7M7ZZfvy3Q_,
    > clientIDPlain=189-5451931-2768662}, Method=WebSearch}
    >
    > eg:
    > adpage=1
    > useragent=NORMAL
    > q=Digital Camera
    > adtest=off
    > mkt=us
    > ch=all-product-search
    > adcount=a3b0c3
    >


    Not too pretty but gets the job done:

    str =~ /Args=\[\{(.*)\}\]/
    hash = Hash[*$1.gsub(', ',',').split(/[,=]/)]


    Diogo
    Diogo Lisboa, Nov 20, 2008
    #2
    1. Advertising

  3. On 20.11.2008, at 20:34 , Raju Alluri wrote:

    > Hi,
    > I have the following text as a string. Can someone tell me a way to
    > extract the Args array in to different key value pairs as listed in
    > the
    > example ?
    >
    > Request={Identities={ImmedCaller={Name=unknown,
    > SubjectID=abcd1:sid:00000000-0000-0000-0000-000000000000}},
    > Args=[{adpage=1, useragent=NORMAL, q=Digital Camera, adtest=off,
    > searchalias=aps, mkt=us, ch=all-product-search, nodeList=, lang=en,
    > adcount=a3b0c3, ip=110.155.15.777}], Service=WebSearchClientService,
    > Metadata={GUID=0Q1C11GKER2MEDM5RQDY, Domain=prod,
    > Host=woe-us-preprod-gp-5106.iad5.xyz.com, AppVersion=*,
    > UserName=nobody,
    > ClientExit=/gp/search/construct-application-context.mi
    > [retail]:.SECOND_PREPARE, ProcessID=23480, TTL=1.0, Sandbox=*,
    > Priority=1.0, DeploymentID=70026525, EnvName=RetailWebsite/US,
    > DepartureTimestamp=Mon Nov 10 17:30:58 GMT 2008, Realm=USXYz,
    > AppName=gurupa, ClientEntry=/gp/search},
    > Shared={sessionID=nNo5yA.xUpGCpgbhuaVn8zG2xXM_,
    > clientID=168v1upXnQTYihGa9iDnty-o9z4_,
    > sessionIDPlain=176-2496192-6342626, customerIDPlain=A2LOKEDOEV0ZP5,
    > customerID=MHuB7vXfQZbKXH9-U7M7ZZfvy3Q_,
    > clientIDPlain=189-5451931-2768662}, Method=WebSearch}
    >
    > eg:
    > adpage=1
    > useragent=NORMAL
    > q=Digital Camera
    > adtest=off
    > mkt=us
    > ch=all-product-search
    > adcount=a3b0c3
    >
    >
    > Thanks in Advance.
    > Raju
    > --
    > Posted via http://www.ruby-forum.com/.
    >



    hash = {}
    data.match(/Args=\[(\{[^}]*)/)[1].scan(/(\w+)=([^,]*)/) do |key, val|
    hash[key] = val
    end

    einarmagnus
    Einar Magnús Boson, Nov 21, 2008
    #3
  4. Raju Alluri

    Mark Thomas Guest

    It's obviously some sort of object serialization format. I can't tell
    exactly which format though. Do you have access to the code that
    created it? There's a chance you'd be able to import it directly into
    a data structure.

    -- Mark.
    Mark Thomas, Nov 21, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. VSK
    Replies:
    2
    Views:
    2,273
  2. David Cho
    Replies:
    4
    Views:
    393
    David Cho
    Feb 15, 2005
  3. Chanchal
    Replies:
    1
    Views:
    486
    NullBock
    Dec 13, 2005
  4. pekka niiranen
    Replies:
    5
    Views:
    505
    Paul McGuire
    Oct 20, 2004
  5. ragz_82
    Replies:
    1
    Views:
    294
    ragz_82
    Aug 4, 2009
Loading...

Share This Page