Loading ...
Sorry, an error occurred while loading the content.

Regular Expression - how do I parse this?

Expand Messages
  • b2174ml
    Can someone tell me how to parse this regular expression?
    Message 1 of 5 , Mar 2, 2006
    • 0 Attachment
      Can someone tell me how to parse this regular expression?

      <CallReceivedEvent callUuid="92b2be68-94af-11da-c59b-00e08101a72a"
      callerId="6304751054" date="2006-02-03 07:21:18" id="34A3D196-441F-
      258C-67F9-F5552D101D94"/>

      I need to get the type of event (CallReceivedEvent), the callUuid (in
      this case, 92b2be68-94af-11da-c59b-00e08101a72a), the date, and the
      id. My main problem is getting the callUuid. How do you pick up a
      value that consists of letters, numbers, and dashes?

      if ($_ =~ m/ what is the rest?

      Thanks in advance.

      Michael
    • merlyn@stonehenge.com
      ... b2174ml Can someone tell me how to parse this regular expression? That s not a regular expression. That s a piece of XML. b2174ml
      Message 2 of 5 , Mar 2, 2006
      • 0 Attachment
        >>>>> "b2174ml" == b2174ml <b2174ml@...> writes:

        b2174ml> Can someone tell me how to parse this regular expression?

        That's not a regular expression. That's a piece of XML.

        b2174ml> <CallReceivedEvent callUuid="92b2be68-94af-11da-c59b-00e08101a72a"
        b2174ml> callerId="6304751054" date="2006-02-03 07:21:18" id="34A3D196-441F-
        b2174ml> 258C-67F9-F5552D101D94"/>

        b2174ml> I need to get the type of event (CallReceivedEvent), the callUuid (in
        b2174ml> this case, 92b2be68-94af-11da-c59b-00e08101a72a), the date, and the
        b2174ml> id. My main problem is getting the callUuid. How do you pick up a
        b2174ml> value that consists of letters, numbers, and dashes?

        You use an XML parser. There are four main families of such in the CPAN:
        using XML::Parser (based on expat), using XML::LibXML (based on libxml2),
        HTML::Parser in XML-mode, and a PurePerl XML parser buried in one of the SAX
        modules.

        Get one of those, and read up.

        --
        Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
        <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
        Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
        See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
      • Victor Bouffier
        given: $line =
        Message 3 of 5 , Mar 2, 2006
        • 0 Attachment
          given:

          $line = <CallReceivedEvent
          callUuid="92b2be68-94af-11da-c59b-00e08101a72a"
          callerId="6304751054" date="2006-02-03 07:21:18" id="34A3D196-441F-
          258C-67F9-F5552D101D94"/>;

          then executing

          if $line =~ /^<(\w+).+?callUuid="(.+?)".+?date="(.+?)".+?\bid="(.+?)"/ {
          $event_type = $1;
          $calluuid = $2;
          $date = $3;
          $id = $4;
          }

          gives you your variables.
          Each parenthesis groups a consecutive numbered variable.
          I believe it would work even if the variables where not in that same
          order, except for event_type, which should be the first one.

          Victor


          On Fri, 2006-03-03 at 02:35 +0000, b2174ml wrote:
          > Can someone tell me how to parse this regular expression?
          >
          > <CallReceivedEvent callUuid="92b2be68-94af-11da-c59b-00e08101a72a"
          > callerId="6304751054" date="2006-02-03 07:21:18" id="34A3D196-441F-
          > 258C-67F9-F5552D101D94"/>
          >
          > I need to get the type of event (CallReceivedEvent), the callUuid (in
          > this case, 92b2be68-94af-11da-c59b-00e08101a72a), the date, and the
          > id. My main problem is getting the callUuid. How do you pick up a
          > value that consists of letters, numbers, and dashes?
          >
          > if ($_ =~ m/ what is the rest?
          >
          > Thanks in advance.
          >
          > Michael
          >
          >
          >
          >
          >
          >
          >
          > Unsubscribing info is here: http://help.yahoo.com/help/us/groups/groups-32.html
          > Yahoo! Groups Links
          >
          >
          >
          >
          >
          >
          >
          >
          >
          >
        • merlyn@stonehenge.com
          ... Victor given: Victor $line = callUuid= 92b2be68-94af-11da-c59b-00e08101a72a Victor callerId= 6304751054 date= 2006-02-03
          Message 4 of 5 , Mar 2, 2006
          • 0 Attachment
            >>>>> "Victor" == Victor Bouffier <victor@...> writes:

            Victor> given:
            Victor> $line = <CallReceivedEvent
            Victor> callUuid="92b2be68-94af-11da-c59b-00e08101a72a"
            Victor> callerId="6304751054" date="2006-02-03 07:21:18" id="34A3D196-441F-
            Victor> 258C-67F9-F5552D101D94"/>;

            Victor> then executing

            Victor> if $line =~ /^<(\w+).+?callUuid="(.+?)".+?date="(.+?)".+?\bid="(.+?)"/ {
            Victor> $event_type = $1;
            Victor> $calluuid = $2;
            Victor> $date = $3;
            Victor> $id = $4;
            Victor> }

            Victor> gives you your variables.
            Victor> Each parenthesis groups a consecutive numbered variable.
            Victor> I believe it would work even if the variables where not in that same
            Victor> order, except for event_type, which should be the first one.

            Nope, you used "." which won't match across newlines.

            Don't use a regex. Use an XML parser.

            --
            Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
            <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
            Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
            See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
          • Victor Bouffier
            Right. XML::Simple would do, I guess? Now, XML::Simple would parse all internals between the opening and closing tags, but you still need the /^
            Message 5 of 5 , Mar 2, 2006
            • 0 Attachment
              Right.
              XML::Simple would do, I guess?

              Now, XML::Simple would parse all internals between the opening and
              closing tags, but you still need the /^<(\w+)/ regex to capture the
              event_type, don't you?

              Anyway, I stand corrected.

              On Thu, 2006-03-02 at 21:00 -0800, merlyn@... wrote:
              > >>>>> "Victor" == Victor Bouffier <victor@...> writes:
              >
              > Victor> given:
              > Victor> $line = <CallReceivedEvent
              > Victor> callUuid="92b2be68-94af-11da-c59b-00e08101a72a"
              > Victor> callerId="6304751054" date="2006-02-03 07:21:18" id="34A3D196-441F-
              > Victor> 258C-67F9-F5552D101D94"/>;
              >
              > Victor> then executing
              >
              > Victor> if $line =~ /^<(\w+).+?callUuid="(.+?)".+?date="(.+?)".+?\bid="(.+?)"/ {
              > Victor> $event_type = $1;
              > Victor> $calluuid = $2;
              > Victor> $date = $3;
              > Victor> $id = $4;
              > Victor> }
              >
              > Victor> gives you your variables.
              > Victor> Each parenthesis groups a consecutive numbered variable.
              > Victor> I believe it would work even if the variables where not in that same
              > Victor> order, except for event_type, which should be the first one.
              >
              > Nope, you used "." which won't match across newlines.
              >
              > Don't use a regex. Use an XML parser.
              >
            Your message has been successfully submitted and would be delivered to recipients shortly.