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

Re: [PBML] Regular Expression - how do I parse this?

Expand Messages
  • Victor Bouffier
    given: $line =
    Message 1 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 2 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 3 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.